Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion sjsonnet/src/sjsonnet/Importer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,16 @@ class CachedImporter(parent: Importer) extends Importer {
val cache: mutable.HashMap[(Path, Boolean), ResolvedFile] =
mutable.HashMap.empty[(Path, Boolean), ResolvedFile]

def resolve(docBase: Path, importName: String): Option[Path] = parent.resolve(docBase, importName)
// Memoize path resolution by (docBase, importName). resolve() runs on every visitImport — before
// the evaluator's by-path Val cache is consulted — and each call stats candidate paths
// (docBase + every jpath) via os.isFile. Resolution is deterministic within a run, so caching it
// turns repeated imports (and re-evaluated import exprs) into a HashMap lookup, eliminating
// redundant filesystem stats. Mirrors the existing read cache.
private val resolveCache: mutable.HashMap[(Path, String), Option[Path]] =
mutable.HashMap.empty[(Path, String), Option[Path]]

def resolve(docBase: Path, importName: String): Option[Path] =
resolveCache.getOrElseUpdate((docBase, importName), parent.resolve(docBase, importName))

def read(path: Path, binaryData: Boolean): Option[ResolvedFile] = {
val key = (path, binaryData)
Expand Down
Loading