Repository navigation
Reuse parsed syntax across RunDir calls - #205
Merged
Merged
Conversation
This was referenced Oct 22, 2026
Listing the Go test collection calls the same Dang module many times. Each call currently reparses its source files. Let callers share an optional syntax cache through the context. Read and hash each file on every use, and keep the parsed tree before type checking. Each call receives an independent copy with its current source paths because type checking mutates syntax nodes. Imports, type checking, initialization and module functions still run for each call. Bound the cache to 128 entries and an estimated 64 MiB. Copy outside the cache lock and fall back to parsing when a syntax layout cannot be copied safely. Cover source changes, source paths, imports, clients and schemas, concurrent calls, eviction and shared references. Add a benchmark using the real Go module source. Signed-off-by: Guillaume de Rouville <[email protected]>
grouville
force-pushed
the
perf/run-dir-syntax-cache
branch
from
October 23, 2026 03:16
4bf229a to
4cc48da
Compare
grouville
marked this pull request as ready for review
October 27, 2026 00:36
Contributor
Author
|
cc @vito @tiborvass |
sipsma
approved these changes
Oct 27, 2026
sipsma
left a comment
Contributor
There was a problem hiding this comment.
Looks good. Each call gets its own copy, the copy carries the caller's paths, and the fallback for unsupported syntax is covered by the corpus test. With no cache in the context, RunDir parses exactly as before.
GitHub hasn't run the Dagger checks on this head yet, so I ran the Go tests through Dagger at 4cc48da: 471 passed in pkg/dang and 823 in tests.
This was referenced Oct 29, 2026
sipsma
added a commit
to grouville/dagger
that referenced
this pull request
Nov 3, 2026
Dang moves from the merge of vito/dang#205 to the merge of vito/dang#213, which adds ParseSourceFile. In between are the v2.2.0 and v2.3.0 releases and vito/dang#214, which change what Dang modules see: - The dang.toml that governs a module's source, found by walking up to the repository root, now sets the Dang version its source parses and evaluates as. A module with none keeps the newest version. A malformed dang.toml, which was ignored before, now fails the module's load. - A module's own top-level declarations shadow builtins of the same name (vito/dang#212). - JSON, YAML and TOML decode into Map[T] (vito/dang#214). - The Dang language skill the engine serves describes these. The engine still chooses a module's Dagger API version itself; the Dagger version a dang.toml can declare doesn't change it. Signed-off-by: Erik Sipsma <[email protected]>
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.
The official Go module is written in Dang. Listing its tests on dagger/dagger calls many module functions, and each call currently parses the same module source again. This remains substantial work after #204.
Add an optional, caller-owned syntax cache to
RunDir, supplied throughWithSyntaxCache. Files are read on every use and entries are keyed by their contents. Dang writes compiler state onto syntax nodes, so the cache keeps a private parsed tree and gives each call an independent copy with its current source paths. Imports, type checking, initialization and module functions still run for every call.Complete command
dagger check --module go --check test --list --allThese are medians of two measured commands per version, in cache / no-cache / no-cache / cache order. Every command starts a fresh CLI after a Go source edit and a unique added test. All return the expected 4,399 rows in order and complete cleanup. Each engine completes a preparation command before timing. Telemetry and normal GC remain enabled; profiling is off.
The selection is the root Go module in dagger/dagger (
test = ["."]), not every nested module. The source isff0b029a. Both versions use engine main at 14c1942, with #14730 and #14738, and Go main atbf45651plus Go #68. They use the exact same Dang library and CLI, including a local stdout-buffer correctness fix, eight CPUs and 40 GiB RAM. Only the native SDK's cache context is enabled or disabled. These are warm-engine results, not first-use engine timings.Cost and implementation
The first use parses the file and prepares a private tree. On the real Go module file, the parser benchmark measured about 139 ms for parsing alone, 146 ms to parse and prepare an entry, and 7 ms for reuse. Preparation allocates about 6% more than parsing alone. These are separate parser measurements, with three samples of 20 iterations each.
The cache retains at most 128 entries with an estimated 64 MiB weight limit. Copying happens outside the cache lock. Unsupported fields or overlapping storage fall back to normal parsing.
This version copies a plain tree instead of building a graph of copy functions. A separate full-command comparison measured 85.01 → 86.13 s, about 1.3% slower than the earlier copier, with essentially unchanged engine CPU and total allocations. The simpler representation is the intended tradeoff. The cache-versus-no-cache measurements above use this final copying code.
Validation
The race checks cover source edits, paths and imports, fresh clients and changed schemas, concurrent evaluation, eviction, fallback and shared references inside a copied tree. Native SDK race checks pass with reuse enabled and disabled.
The small native SDK integration supplies the cache context and needs this API before it can land.