Skip to content

perf(dang): reuse decoded API schemas for native calls - #14808

Merged
tiborvass merged 1 commit into
dagger:mainfrom
grouville:perf/native-dang-schema-decoding
Oct 27, 2026
Merged

tiborvass merged 1 commit into
dagger:mainfrom
grouville:perf/native-dang-schema-decoding

Conversation

@grouville

Copy link
Copy Markdown
Member

Listing Go tests makes many native Dang calls while discovering packages and their tests. Each call opens and decodes its API schema, even when other calls have already decoded the same immutable file. In the latest full-listing profile, decoding schemas accounted for about 32 CPU-seconds across 1,602 native calls. That is CPU time summed across concurrent calls, not 32 seconds of command time.

Reuse the decoded schema through the existing DagQL cache, keyed by the schema file ID. Each call keeps its own schema wrapper and list of types, so adding module-local types cannot affect another call. Clients, type inference and execution remain separate. No new lock or LRU is added.

This is part of the work to make Go collection listing faster.

dagger check --module go --check test --list --all
Case Complete command, before → after Total allocations, before → after
Root Go module in dagger/dagger, 4,399 rows 76.88 → 72.55 s 53.98 → 48.99 GB
Small repository, nine rows 0.967 → 0.892 s 307.72 → 285.53 MB

The full listing saves about 4.3 seconds, or 5.6%. Engine CPU time falls from 366.86 to 331.54 CPU-seconds. These are medians from two warm measurements per version in A–B–B–A order; the small control has eight measurements per version. Every command starts a fresh CLI after source and test edits, returns all expected rows in order, and completes cleanup. Telemetry and normal GC remain enabled. Each engine completes a preparation command before timing.

The cost is holding decoded schema metadata while a session uses it, plus copying the outer wrapper and type list for each call. The existing cache releases that metadata after the last session using it ends. Sampled engine-container memory was 16.34 → 15.85 GB for the large case and 2.21 → 2.25 GB for the small control; these samples do not establish a peak-memory improvement.

Measurement setup

The full selection is the root Go module in dagger/dagger at ff0b029a, with test = ["."], not every nested module. There are 4,398 existing rows plus the test added for each measurement.

Both timed versions use engine 14c1942, with #14730, #14738, #14806, the merged Dang parser improvement and Dang #205 held constant. The full case uses Go main at bf45651 plus Go #68; the small control uses that Go main without #68. Both use the same development CLI, including a common stdout-buffer correctness fix, and the same retained cache with eight CPUs and a 40-GiB limit. Profiling is off during measurements; no cache reset or forced GC is used.

Only decoded-schema reuse differs. These numbers measure its contribution on that stack, not a comparison with stock main. The PR itself is a standalone change on current upstream main.

The tests cover concurrent calls using different clients, isolation of module-local types, separate schema files, retry after a failed read, and release after the last session ends. They also check that evaluating imports leaves the shared schema metadata unchanged. The SDK race suites pass on the benchmark stack and on the standalone upstream-main branch.

go test -race -p=2 -buildvcs=false ./core/sdk/dang/v2 ./core/sdk/dang/shared

@grouville
grouville force-pushed the perf/native-dang-schema-decoding branch 2 times, most recently from 8994a8f to cb5c900 Compare October 23, 2026 08:42
@grouville
grouville marked this pull request as ready for review October 27, 2026 17:09
Every native Dang call decodes its API schema before running the module.
Go test discovery repeats this for each package, even when the calls use
the same immutable schema file.

Reuse the decoded metadata through the existing DagQL cache, keyed by the
schema file ID. Keep a separate schema wrapper and type slice for each
call, since module initialization can append its own type placeholders.
Clients, type inference and evaluation remain local to each invocation.
The cached metadata is released after the last session using it ends.

Cover concurrent calls with different clients, module-local type changes,
different schema files, failed reads and session cleanup.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the perf/native-dang-schema-decoding branch from cb5c900 to 97bd0d7 Compare October 27, 2026 17:52
@tiborvass
tiborvass merged commit 0dd7792 into dagger:main Oct 27, 2026
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants