Commit e10ccc6
authored
perf: abstract FormatCache as pluggable trait, optimize format runtime (#679)
## 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 `FormatCache` trait, allowing
parsed format specifications to be cached and reused across calls. The
default implementation provides a simple LRU-style cache.
## Modification
- Add `FormatCache` trait with pluggable cache strategy
- Cache parsed format specifications keyed by format string
- Optimize format runtime dispatch for common patterns
- ~317 lines changed
## Benchmark Results
### JMH (JVM, 3 iterations warmup + 3 measurement)
| Benchmark | Master (ms/op) | This PR (ms/op) | Change |
|-----------|---------------|-----------------|--------|
| bench.02 | 50.427 ± 38.9 | 45.984 ± 2.4 | **-8.8%** |
| comparison2 | 85.854 ± 188.7 | 69.734 ± 19.9 | **-18.8%** |
| realistic2 | 73.458 ± 66.7 | 70.857 ± 3.2 | **-3.5%** |
## 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
- Upstream: jit branch experiment
## Result
All 5 tests pass. All benchmarks positive, no regressions.1 parent cfbb1a1 commit e10ccc6
6 files changed
Lines changed: 317 additions & 104 deletions
File tree
- sjsonnet
- src-jvm-native/sjsonnet
- src/sjsonnet
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
| 376 | + | |
| 377 | + | |
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
1270 | 1271 | | |
1271 | 1272 | | |
1272 | 1273 | | |
1273 | | - | |
1274 | | - | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
1275 | 1277 | | |
1276 | 1278 | | |
1277 | 1279 | | |
| |||
0 commit comments