Skip to content

Commit c0bc815

Browse files
committed
perf: abstract FormatCache as pluggable trait, optimize format runtime
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)
1 parent 3ff6d95 commit c0bc815

6 files changed

Lines changed: 317 additions & 104 deletions

File tree

sjsonnet/src-jvm-native/sjsonnet/SjsonnetMainBase.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ object SjsonnetMainBase {
373373
logger = warnLogger,
374374
std = std,
375375
variableResolver = _ => None,
376-
debugStats = debugStats
376+
debugStats = debugStats,
377+
formatCache = FormatCache.SharedDefault
377378
) {
378379
override def createEvaluator(
379380
resolver: CachedResolver,

sjsonnet/src/sjsonnet/Evaluator.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class Evaluator(
2222
val wd: Path,
2323
val settings: Settings,
2424
logger: Evaluator.Logger = null,
25-
val debugStats: DebugStats = null)
25+
val debugStats: DebugStats = null,
26+
override val formatCache: FormatCache = FormatCache.SharedDefault)
2627
extends EvalScope {
2728
implicit def evalScope: EvalScope = this
2829
def importer: CachedImporter = resolver
@@ -1256,8 +1257,9 @@ class NewEvaluator(
12561257
private val w: Path,
12571258
private val s: Settings,
12581259
private val wa: Evaluator.Logger = null,
1259-
ds: DebugStats = null)
1260-
extends Evaluator(r, e, w, s, wa, ds) {
1260+
ds: DebugStats = null,
1261+
fc: FormatCache = FormatCache.SharedDefault)
1262+
extends Evaluator(r, e, w, s, wa, ds, fc) {
12611263

12621264
override def visitExpr(e: Expr)(implicit scope: ValScope): Val = try {
12631265
(e.tag: @switch) match {

0 commit comments

Comments
 (0)