Skip to content

perf(dagql): avoid caching reflected primitive getters - #14806

Merged
grouville merged 2 commits into
dagger:mainfrom
grouville:perf/reflected-scalar-getters
Oct 27, 2026
Merged

grouville merged 2 commits into
dagger:mainfrom
grouville:perf/reflected-scalar-getters

Conversation

@grouville

@grouville grouville commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

I was profiling Go test collection listing in dagger/dagger with wcprof. After discovering the tests, the engine still spent substantial time reading fields such as each dimension's name and key. Reading the field is cheap, but DagQL creates and keeps a separate cached result for it. That bookkeeping costs more than the read.

Use the existing uncached-call path for automatically generated getters of plain String, Int, Float and Boolean fields. These getters only read their immutable receiver. Each getter still runs and keeps its normal call tracing. The change adds six production lines and no cache, lock or shared state. Objects, lists, optional values, custom scalars and resolver functions retain their current behavior.

Full Go collection listing

dagger check --module go --check test --list --all

I compared the same development engine with and without these six lines. All eight measured commands returned the complete expected 5,199 rows, in order, and closed their sessions successfully.

Four warm runs per version Before After
Complete CLI command, median 56.11 s 43.96 s
Complete CLI command, range 52.25–60.72 s 42.58–46.73 s
Engine CPU, median across all cores 269.13 CPU-s 229.30 CPU-s
Cumulative engine allocation, median 45.81 GB 39.84 GB

That is 22% less elapsed time, 15% less engine CPU and 13% fewer allocated bytes. Every pair improves; no samples were discarded. Mean elapsed time also improves, 56.30 → 44.31 s.

The first two pairs were a screen; after both improved, I added two validation pairs. The order was before, after, after, before, before, after, after, before. Each command starts a fresh CLI after source and test edits. Each engine switch retained the same disk cache after graceful shutdown and completed an unprofiled preparation. Telemetry, ordinary GC and the eight-CPU / 40-GiB limits stayed unchanged. Profiling was off; output, cleanup, background-work and resource checks passed.

These numbers are conditional on a shared development stack, rather than plain main: engine 1e0512b6, based on main d5f68c6, includes #14802, #14738, #14808, experimental sharing of installed schemas, Dang #205 and common integration patches. Both versions use the same CLI (2b99fcb9, including the local stdout correctness fix) and Go module b3631f19 (main c25c457 plus Go #68, including Erik's merged discovery changes). Only this PR differs between the engines; the new Dang callback optimization is excluded from both.

The fixture is dagger/dagger ff0b029a, root Go module with test = ["."]: 800 package checks, 4,398 existing tests and one test added per measurement. This does not measure every nested module or a cold engine.

Cost and correctness

The cost is repeating a struct-field read when the same field is requested again. A previous warmed-query probe with real core.AroundFunc tracing showed no slowdown from that repetition.

Lower allocation does not guarantee a lower memory peak. Sampled engine peaks overlap: 11.94–13.32 GB before and 11.47–13.75 GB after. Two candidate peaks were higher than their paired controls.

The behavioral test reads all four scalar types twice, checks their values and verifies all eight tracing callbacks without cache hits. It fails without the change. The field-policy test covers object, list and optional fields. The full standalone DagQL race suite passes; the focused tests also pass on the exact combined engine above.

go test -race -count=1 ./dagql

To exercise the listing workload in scratch checkouts, use dagger/dagger ff0b029a and grouville/go b3631f19 in sibling directories fixture and go-module. Put this in fixture/dagger.toml:

[modules.go]
source = "../go-module"
[modules.go.settings]
version = "1.26.6"
goflags = "-p=8"
test = ["."]

From fixture, point the same CLI at each engine with _EXPERIMENTAL_DAGGER_RUNNER_HOST. Run a complete preparation, then time the listing command after edits to dagql/types.go and dagql/cache_test.go. Verify complete output and successful exit. Keep engine resources, the Go checkout and the CLI identical. Absolute times depend on the engine stack and machine.

Reading a plain string, integer, float or boolean field is cheaper than
publishing another cache result for the read. Use the existing uncached
path for those reflected getters. Getter execution and normal tracing stay
enabled. Object, optional, list and custom scalar fields keep their policy.

A complete warm edited Go test listing improves 87.20s to 76.05s in a balanced
comparison. Both versions return 4,399 rows and complete cleanup. The smaller
nine-row control stays near one second. Engine CPU and allocation improve
in the full listing; peak container memory is not lower in this cohort.

Extend the field-policy fixture and add one behavioral test for values,
tracing callbacks and repeated-read cache outcomes. The behavior test fails
without the six-line policy. The full DagQL race suite passes.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the perf/reflected-scalar-getters branch from d66e8a1 to 56af4a8 Compare October 23, 2026 09:40
Scalar getters use DoNotCache to avoid cache overhead. This flag
also makes the telemetry path emit a span for each call. Repeated
reads of the same field produce duplicate spans and logs.

Add a separate flag to keep span deduplication for these getters.
Pass it from the field spec to the call request and preserve it
when the request is cloned. Keep repeated traces for fields with
an explicit DoNotCache policy. Keep the WithRepeatedTelemetry
reset behavior.

Test real field selections with core.AroundFunc. Check the span
count, returned value, and absence of cache hits. Also check
request clones and explicit cache policies.

Signed-off-by: Tibor Vass <[email protected]>
@tiborvass
tiborvass marked this pull request as ready for review October 27, 2026 14:33
@grouville
grouville merged commit 2a21828 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.

2 participants