Skip to content

perf(clientdb): avoid rescanning children for new spans - #14738

Merged
tiborvass merged 2 commits into
dagger:mainfrom
grouville:perf/review-span-child-index
Oct 27, 2026
Merged

tiborvass merged 2 commits into
dagger:mainfrom
grouville:perf/review-span-child-index

Conversation

@grouville

@grouville grouville commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Listing Go tests in dagger/dagger creates many spans under the same query. Each new child currently scans the query's existing children to reject duplicates. A captured listing had 53,749 children under one query; across that trace, those scans require about 1.47 billion string comparisons.

Use the existing parent map to recognize a new span ID and append it directly. Keep the duplicate check for IDs reused across traces. For cause links, check the span's own targets instead of every span linked to the same target. Both directions are already recorded together under the same lock. This adds no map, lock or retained state.

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

Standalone measurement on main

I replayed the actual 225,955 span snapshots against engine main at 14c1942, with only this change applied to the candidate.

Building the span index Main This change
Process CPU time 12.43 s 3.69 s
Allocated bytes 294.58 MB 294.63 MB

These are medians of two replays per version, in opposite orders. Every index and child order matches. Reading and decoding the capture are outside the measurement. The host was busy, so these numbers measure CPU work rather than elapsed command time.

Effect on a full listing

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

A CPU profile covering final shutdown also found about 8.3 CPU-seconds in the sibling scan. The unpatched command then repeatedly reached the CLI's 10-second deadline while flushing traces. It returned the correct rows but exited with a cleanup error.

With this change, three warm listings completed in 84.10–85.13 s, including all 4,399 expected rows and cleanup. One of those runs spent 0.39 s flushing traces. Returning to the unpatched engine reproduced the 10-second flush timeout.

This establishes a useful effect on completion. It does not establish a paired full-command speedup: the unpatched commands failed, so their times are excluded.

These full runs use main at 14c1942, with #14730, the parser from Dang #204, and Dang #205 common to both versions. The Go module is merged main at bf45651 plus Go #68. The source is dagger/dagger at ff0b029a, with test = ["."] selecting the root Go module. Each command starts a fresh CLI after source and test edits. Both versions use the same CLI, including a local stdout-buffer correctness fix, eight CPUs, 40 GiB RAM, normal telemetry and GC, and profiling off.

Tests

The full engine/clientdb race suite passes on 14c1942. The added test covers repeated snapshots, IDs reused across traces, late parents and cause links, and child order.

go test -race -count=1 ./engine/clientdb
go test ./engine/clientdb -run '^$' -bench '^BenchmarkSpanLookupFanout$' -benchmem

@grouville
grouville force-pushed the perf/review-span-child-index branch 3 times, most recently from 800965a to 9ee81f8 Compare October 22, 2026 05:42
@grouville
grouville force-pushed the perf/review-span-child-index branch from 9ee81f8 to 24446e4 Compare October 23, 2026 05:18
@tiborvass
tiborvass marked this pull request as ready for review October 27, 2026 18:41
@tiborvass
tiborvass force-pushed the perf/review-span-child-index branch 2 times, most recently from 1ad67a1 to 200ae7f Compare October 27, 2026 19:37
grouville and others added 2 commits October 27, 2026 14:16
Go test collection listing produces wide traces. Adding each new child
currently scans its siblings to reject duplicates, so the work grows
quadratically with the number of children. A real dagger/dagger listing
recorded more than two billion such comparisons.

Use the existing parent map to recognize new span IDs. Keep the old scan
for IDs repeated across traces. For cause links, check the existing reverse
index instead of every span linked to the same target. Both directions are
updated together under the existing lock.

Add a compatibility test for repeated IDs and late parents/links, plus a
benchmark that builds a fresh index at several widths. No additional map,
lock or retained state is introduced.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the perf/review-span-child-index branch from 200ae7f to dfa7ebc Compare October 27, 2026 21:16
@tiborvass
tiborvass merged commit 01ef75d 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