Repository navigation
state_exec locks: L1's speed (deadlock search, uncontended path, restated gate) - #1175
Merged
Merged
Conversation
…requester block() ran 4.6's "P in reach(targets)" as a depth-first search from every target, recomputing each process's successors (every overlapping waiter) as it went. At p waiters on one key, each re-queue after a handoff searched the whole queue from every earlier waiter: O(p^2) work and an allocation per node, about 90 us per handoff at p = 64 on the bench box. Every edge into P comes from a queued ticket that conflicts with a hold of P: P has no ticket in block(), and its request would queue last (protocol 3.2). So a requester with no hold cannot be on a cycle, and the search is skipped. Otherwise the processes with a path to P are found first, backwards through predecessors(), and the search runs only when a target is among them, confined to them. A process with no path to P reaches only processes with none, so the confined search finds a cycle exactly when the full one does, and the same first path: the DeadlockError's cycle is unchanged. lock.handoff at p = 64: 92-93 us per handoff before, 12-14 us after (medians of 6 runs, base and candidate interleaved, loaded box); steps per handoff unchanged (37.0). Protocol 4.6 gains the implementation note; LD-11 checks a cycle found past targets that cannot lead back, and twenty waiters that hold nothing queueing with no false deadlock.
… work Cycle counters over lock.uncontended's loop put an uncontended lock's cost roughly 40% in the evaluator's glue, 25% in the lock home and 30% in the manager, with no single hot spot. This cuts what needs no protocol change: - lock_home: scope_id remembers its last answer (a program locks under one chroot), and a 16-slot memo keyed by the address of the key's text sits in front of the key cache's unordered_map. A memo slot is a hint: it is taken only when that entry is live and holds the same scope and text, and the live entries are exactly those in the index. - lock_table: begin_op no longer copies the seeds while no home lends (only relevel_all's lending paths read them); the request's key text is built only for the self-check's cross-check; try_acquire looks the record up once, and new_hold takes the record and returns the hold, so neither is looked up again. - stackless_evaluator: step_init hands the lock_ops it found to begin_lock_form, which hands it to lock_acquire, so the fast path derives it once with no value_t copy (two derivations per lock with the release, down from five). Restored frames still read it from the frame's slot. Probe of the home and table (best of 25 loops of 100k, three interleaved rounds against master 2b2b976, pinned, loaded box): the scope and key-cache lookups 29-45 ns -> 11-13 ns, building the request 56-72 -> 43-45 ns, the whole home path 242-307 -> 232-262 ns. Steps and allocations per lock are unchanged (0 and 0); timing gates wait for a quiet window.
…s cost Design 8.8's 25-50 ns (65-90 shared) estimate for an uncontended lock leaves out the record each section makes and drops, two index updates, two pools, the operation framing and the evaluator's frame layout; the manager alone takes 140-180 ns single and 190-235 ns shared on the development laptop. 11.3 records the breakdown (evaluator glue ~40%, home ~25%, manager ~30%), the 64-waiter handoff cost the deadlock search was (92-93 us, now 12-14 us), and what reaching 11.2's 60/120 ns would take (a leaner fast path that changes protocol 4.1, or a restated gate: the owner's decision). The sharding decision is unchanged: lock.cross_thread is measured again in a quiet window first.
…ecture The owner's decision (2026-11-12), between a leaner fast path that changes protocol 4.1 and a gate restated from what the design costs: the gate is restated. An uncontended with-lock may cost at most 450 ns over begin in single mode and 550 ns in shared mode (sync, flat key, Release, quiet window, noise at most 10%), against the 60 and 120 ns first set from design 8.8's estimate. 0 steps and 0 allocations per lock stay the hard gates, as CTest runs them. The numbers come from three sources: - the probe's best runs: the manager and home together are 230-250 ns single and 270-290 ns shared; - the evaluator's share on top of that; - the lowest of the bench's own runs on a loaded box (sync, best of 100 short runs per side): 230-305 ns single and 310-360 ns shared. The first run in a quiet window checks them. Design 11.1-11.3 and STATE_EXEC_BENCH.md's gate commands follow; 11.3's L3 record keeps its numbers, marked as the gates of that time.
transfix
marked this pull request as ready for review
November 14, 2026 21:17
…for the singleton scan)
A PR's Debug ctest gives every test without a TIMEOUT property 300 s (ci.yml, --timeout 300, three tries). Three of ocean_ewave_test's long runs (NoFluxWallsAreLossless, AThinWallLeaksLittle, AMovingSourceLeavesAKelvinWake) take 105-195 s each in Debug on an idle runner, so a busy one misses 300 s on every try: on 2026-11-14 that made package-linux / libcvc-debug red on two unrelated PRs (feat/ariadne-live-textures, p1/skeleton-surfaces). The suite's own 1200 s keeps a real hang caught and stops the runner's load from failing PRs. (cherry picked from commit 83e7536)
transfix
added a commit
that referenced
this pull request
Nov 16, 2026
…#1307) One conflict, in ariadne_runtime_test.cpp's ActionCapsAreTreeSettingsAndChargeAsyncCalls: this branch cut its loop to 20 rounds so it fit the 0.1 s time cap on Linux debug CI, and master (#1282) rewrote the test, raising the time cap to 30 s wherever the loop must finish. Master's fix covers the same flake, so the test is master's as it stands, 200 rounds again. tools/singleton_scan is master's (#1276); the auto-merged net, CI, test and doc files keep both sides.
This was referenced Nov 16, 2026
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.
This PR fixes the two
with-lockbench findings open since L1 (#862). It needs no protocolchange. The plan and the full measurements are in the workstreams tracker:
state-exec-perf/locks-impl/L1-speed.md.Finding 2: the deadlock search at 64 waiters (fixed)
block()ran protocol 4.6'sP in reach(targets)as a depth-first search from every target. Itrecomputed each process's successors (every overlapping waiter) as it went. With p waiters on
one key, every re-queue after a handoff searched the whole queue from every earlier waiter:
O(p^2) work, plus an allocation per node.
Every edge into P comes from a queued ticket that conflicts with a hold of P. P has no ticket in
block(), and its request would queue last (3.2).lock.handoffcase.
predecessors(). The search runs only if a target is among them, and only over them. Aprocess with no path to P reaches only processes with none, so the cycle found (or not) is
the same one, and so is the
DeadlockError'scycle.Protocol 4.6 gains this as an implementation note. LD-11 checks a cycle found past earlier
targets that can't lead back, and 20 waiters that hold nothing queueing with no false deadlock.
lock.handoff(workers=host)The times are medians of 6 runs, base and candidate interleaved, on a loaded box.
Finding 1: the uncontended lock (reduced; gate restated)
Cycle counters inside the lock path put an uncontended lock's cost at about 40% evaluator glue,
25% lock home and 30% manager. There is no single hot spot. This PR cuts what needs no
protocol change:
scope_idremembers its last answer. A 16-slot memo, keyed by the address ofthe key's text, sits in front of the key cache. A memo entry counts only when it is live with
the same scope and text.
one record lookup per
try_acquire.new_holdtakes the record and returns the hold.value_t.That is two derivations per lock, down from five.
Probe of the home and table (a temporary test, not committed): best of 25 loops of 100k,
pinned, three rounds interleaved against master, medians. The box was loaded.
try_acquire+release, single (depth 1 / 4)build_requestThe gate, restated (the owner's decision, 2026-11-12). Design 8.8's 25-50 ns estimate left
out the record each section makes and drops (4.1's
ensure_recandmaybe_drop_rec). It alsoleft out two index updates, two pools, the operation framing and the evaluator's frame layout.
An uncontended lock touches about ten structures twice. The gate is now restated from that
measured architecture. A leaner fast path that changes protocol 4.1 was the other option, and
was not taken.
The restated gate: at most 450 ns over
beginsingle and 550 ns shared (sync, flatkey, Release, quiet window, noise ≤ 10%). It was 60 and 120 ns. 0 steps and 0 allocations
stay the hard gates, run in CTest. The numbers come from three sources:
shared;
230-305 ns single and 310-360 ns shared.
The first run in a quiet window checks them. Design 11.1-11.3 and
STATE_EXEC_BENCH.md's gatecommands follow (faa024c). The sharding decision is unchanged:
lock.cross_threadis measuredagain in a quiet window first.
Counts and tests (Windows, MSVC 19.44 Release, local cvcpkg prefix)
state_exec_bench_gates, run by hand: every gate passes. That is 0 steps and 0 allocationsper lock at every
form=singlepoint (both schedulers, both threading modes), and the pinnedsched.single.*steps_totalvalues.state_exec_locks_test(-*Stress*, LocksThreads, LocksReview and LD-11 included): 211/211.LocksStress locally: 6/6 pass (LT-4 with 1000 fuzz seeds, LT-10 with 10^5 operations, and the four LK-18 cases at 10^5).
locks-deep.ymlis dispatched on this branch (run 43186202693).state_exec_locks_model_test(-*Stress*): 178/178.state_exec_priority_test(the PI cases): 40/40.bindings/pycvc/test_pycvc_state_exec_locks.py: OK.Left for a quiet window
The timing A/Bs:
lock.uncontended,lock.cross_threadand thelocks=noneregressionfamilies against master 2b2b976. On this box the uncontended medians moved ±30% between
interleaved rounds, so wall time gives no verdict here.