perf: abstract FormatCache as pluggable trait, optimize format runtime#679
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: abstract FormatCache as pluggable trait, optimize format runtime#679He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
He-Pin
commented
Apr 5, 2026
Extract format string cache from static field in Format.scala into a pluggable FormatCache trait (analogous to ParseCache). This allows users to supply custom cache implementations (e.g., Caffeine-based) via the Interpreter/Evaluator constructors. Key changes: - New FormatCache trait with getOrElseUpdate API - DefaultFormatCache: LRU LinkedHashMap (256 entries), thread-safe - FormatCache.SharedDefault singleton preserves process-wide sharing - FormatCache.EmptyCache for testing - CompiledFormat sealed trait for type-safe opaque cache entries - RuntimeFormat: direct Val dispatch, Long fast path, pre-cached specs - PartialApplyFmt pre-parses at construction time (no cache needed) - FormatCache threaded through Interpreter → Evaluator constructors Upstream: he-pin/sjsonnet jit branch (format optimization commits)
9ffd530 to
c0bc815
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The
%format operator in Jsonnet is commonly used in string-heavy workloads (e.g., realistic2). Each format call re-parses the format string, which is wasteful when the same format pattern is used repeatedly.Key Design Decision
Abstract format string parsing into a
FormatCachetrait, allowing parsed format specifications to be cached and reused across calls. The default implementation provides a simple LRU-style cache.Modification
FormatCachetrait with pluggable cache strategyBenchmark Results
JMH (JVM, 3 iterations warmup + 3 measurement)
Analysis
The format cache helps most on comparison2 (-18.8%) which has repeated format patterns. The realistic2 improvement is modest (-3.5%) because its format patterns have more variety. The infrastructure enables further optimizations on format-heavy workloads.
References
Result
All 5 tests pass. All benchmarks positive, no regressions.