Repository navigation
Conversation
sipsma
force-pushed
the
sipsma/dagql-hit-read-lock
branch
4 times, most recently
from
October 30, 2026 19:01
3ea308c to
6f68e1a
Compare
A cache hit still took egraphMu for writing on two paths that, for a repeat hit, change nothing: a hit that might teach the e-graph its identity (extra digests, TTL, persistable, or a structural route) repeated its lookup under the write lock, and a persistable hit upserted its persisted edge under the write lock. usesPartAcquisition took the write lock on every call for results that host parts. In an edit build, where nearly every request is a cache hit, those writers queued the request goroutines' read locks behind them. - A hit whose identity teaching would change nothing (the request's digests already in the result's single output class, the result already associated with the request's term, every term with that digest already pointing at that class, the result already posted under its recipe and extra digests, the expiry unchanged) is now answered and claimed under the read lock. Anything else still repeats the lookup under the write lock. - A persistable hit's persisted-edge upsert takes the write lock only when the edge is missing or its expiry would change. - usesPartAcquisition answers under the read lock when the result has no part state at all or its gate is already managed; only starting to manage a gate takes the write lock. The read-only checks find roots without path compression and answer "changes something" whenever a step would write. Signed-off-by: Erik Sipsma <[email protected]>
PersistHit held egraphMu for writing in every case. The code now checks under the read lock whether the result is collected or already persisted, and then changes nothing, so only an upsert that changes the edge waits for open read sections. In the "atomic" sections mode WriteLockAvailable is always true, so those configurations are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
usesPartAcquisition's read-locked fast path covered a row with no gate and no part state, and a managed gate. A row whose gate exists but is not managed, with no part state or with a group still evaluating, still took the write lock only to answer false. The fast path now follows the write path's order exactly, so only starting to manage a gate takes the write lock. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
It makes one read-only check for each write the hit's write path could make, which takes it past gocyclo's limit of 30, as other long sections under the graph lock are. Signed-off-by: Erik Sipsma <[email protected]>
TestSnapshotOwnerWaitsForWholeContainer built the cycle between a diagnostic holding the graph read lock, a snapshot owner reader and a Container's whole body by waiting for the body's dependency evaluation to queue for the graph write lock in usesPartAcquisition. That call now answers under the read lock, which another reader doesn't block, so the wait never came. A queued writer still holds off new readers, as one always can on a busy engine, so the test now queues a real writer behind the diagnostic and waits for the body's evaluation to queue for the read lock behind it. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/dagql-hit-read-lock
branch
from
October 30, 2026 20:53
6f68e1a to
f6423f5
Compare
Contributor
Author
|
Superseded by #15007, which carries these commits unchanged. |
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.
What this changes for users
Rebuilding after an edit is faster. Building dagger's CLI with a per-package Go build, an edit inside the module was 0.14 s faster and an edit of the CLI's own package 0.20 s faster. The walk over cached packages before the first real compile was 0.136 s shorter. A first build and an unchanged rebuild didn't change.
These were measured on an engine built from main as of 27 Oct with #14866 and #14872 applied, not on this branch's base. The lock code this change touches is the same on both.
Why
In an edit build, nearly every request is a cache hit. #14892 let most hits share the cache's global lock,
egraphMu, but some hits still took it for writing, and so didusesPartAcquisitionfor every result that hosts parts. Writers make every reader wait, so the request goroutines queued behind them.What changes
A hit now takes the write lock only when it actually changes something:
usesPartAcquisitionanswers under the read lock whenever its answer needs no write; only starting to manage a part gate takes the write lock.The read-only checks find equivalence-class roots without path compression, which is a write, and answer "changes something" whenever a step would write. Each check's read point is where the hit is ordered: a write that lands after it orders after the hit, which was already a legal order.
Measurements
dagger's CLI with dagger.io/go's per-package build, on the earlier engine described above, with and without this change. One 16-core AWS machine (c8gd.4xlarge), a fresh engine per run, 3 interleaved runs per arm, medians:
Lock waits per edit, summed over request goroutines, from separate runs with Go's block profile:
Testing
engine-dev test --pkg ./dagql --race, 1,234 tests. So do thecorepackage tests, 2,569 of them.TestCacheReadPathsShareEgraphLockandTestCachePartAcquisitionAnswersUnderReadLock. Each runs the path while another goroutine holds the read lock, so a path that takes the write lock fails:usesPartAcquisitionwith no part state, with an unmanaged gate, and with a managed gate.TestSnapshotOwnerWaitsForWholeContainerguards an earlier deadlock fix, and it built that deadlock by waiting forusesPartAcquisitionto queue for the write lock. This change takes that call off the write lock. The test now queues a real graph writer behind the diagnostic's read lock and waits for the evaluation's read lock to queue behind that writer. A queued writer can always do this on a busy engine. With the deadlock fix reverted, the test still fails.The TLA+ model
PersistHitnow needs the write lock only when it changes the result, i.e. when the result is registered and not yet persisted. Identity teaching and part gates aren't modeled, so those two changes need no model update."split"sections mode with persistable requests. In the"atomic"mode, write sections are never blocked, so every other configuration is unchanged.shared_claims_prunepasses, at 309,115,892 distinct states, the same count as before the model change;shared_claims_resourcespasses, at 52,014,149;shared_claims_prune_stale_edgestill violatesOwnershipExact, as it must.