Repository navigation
perf(evidence): build related-test context facts in parallel chunks (#12947) - #14892
Conversation
…12947) CompactGripContext construction computed every test's pure facts serially (about 4.8 s for ripr-swarm's 30,669 tests on a cold check). Compute them in chunks of 512 over rayon, then fill the posting maps, file value scans and CompactTest records serially in test order, so every map and vector is identical to the serial build. Cancellation is checked once per chunk before fan-out and once per test in the in-order pass. On a rayon worker the build stays in line under the #8756 nested-parallelism guard, whose re-export is no longer test-only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNUoLWvJLNTjPAkUKhsj5V
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 41 minutes. View limit details
|
There was a problem hiding this comment.
Code Review
This pull request parallelizes the computation of per-test context facts in chunks using Rayon, while maintaining serial order when filling shared lookup tables. This optimization reduces the time spent preparing evidence in large workspaces. Additionally, comprehensive unit tests have been added to ensure parallel builds match in-line builds. The review feedback correctly identifies that is_multiple_of is an unstable Rust feature and suggests replacing it with the standard modulo operator (%) to prevent compilation failures on stable Rust.
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY
Head: d92f163. Reviewed read-only by a fresh reviewer who did not write the change; nothing blocks.
Purity. I traced every function the parallel facts_of closure reaches: the helper-owner call-name family, the import-affinity scans, module_path_for_index, package_scope, module_stem and crate_root_file_key. None of them reads an overlay, the committed-source view, run_memo, the cancellation token or the filesystem. Only two thread-locals are reached: MASK_MEMO, a content-compared pure cache, and a #[cfg(test)] counter. The checkpoint closure is never captured by the parallel part.
Ordering. In the old loop, the only state carried between tests was the posting maps and file_value_scans. Both stay in the in-order serial pass. Rayon's indexed collect keeps chunk order, and test_index equals the old enumerate index.
Cancellation. Every checkpoint()? returns Err, and EvidencePass::new maps that to None. A cancelled build is never partial and never marked complete. owned_deadline_stops_context_test_loops_without_completing_context still stops at the same observation count.
Tests.
parallel_context_build_matches_the_in_line_buildcompares the off-pool and pool builds field by field over 1,465 tests in 3 chunks.- An independent in-order rebuild of the posting maps and the index-order identity check rule out facts zipped onto the wrong test.
- The fan-out test pins both branches, and forcing fan-out off fails both tests.
Non-blocking.
- On a pool worker, cancellation can now land up to one 512-test chunk later (about 80 ms). The PR body discloses this.
- The deadline test pins the stop count, not the position of each check.
- Gemini's
is_multiple_offinding is answered on its thread: the method is stable since Rust 1.87, and the MSRV here is 1.95.
Proof:
cargo xtask precommitexits 0.- 647
test_grip_evidence::lib tests pass. - JSON
cmpis identical across 10 cold and warm runs. - Cold
evidence_contextdrops from about 9.3 s to 5.9 s. - Not run locally: the full workspace suite. Hosted CI covers it.
Generated by Claude Code
EffortlessSteven
left a comment
There was a problem hiding this comment.
VERDICT: APPROVE d92f163 — no blocking findings on this head.
Exact-head review of #14892 (base e403f8dc, head d92f1635, 3 files, +451/−113). All hosted checks are green on this head: Rust gates, all four Rust tests shards, shards verify, Admit PR Candidate, Ripr Rust Small Result.
Claim. CompactGripContext::build computes each test's pure context facts in chunks of 512, on the rayon pool where nesting is allowed, then fills the posting maps and CompactTest list in original test order; output and ripr check bytes are unchanged.
Why it holds.
ContextTestFactsis derived only fromindex, theTestSummary, and whole-index tables built before the loop. The context's ownMutex/OnceLockcaches (parsed_sources,owner_lookups,shared_grips,pin_syntax, ...) are fields of the not-yet-constructedCompactGripContext, so no per-test fact function can take one of those memo locks while a sibling chunk is queued. The alternate deadlock shape the guard exists for (#8756) therefore cannot arise here, andnested_parallelism_allowed()(rayon::current_thread_index().is_none()) still forces a build that runs on a pool worker to stay in line.- The parallel map is an indexed
par_itercollected intoVec, which preserves chunk order, andchunk.iter().zip(chunk_facts)then posts in global test order. Every posting map,file_name_countsandtestsare therefore built in the same order as the serial loop. file_value_scansArcsharing is preserved: the entry is created at the same point in struct construction (last field), so tests in one file still share oneOnceLock.- The file-key branch is unchanged in substance (
Stem, elseCrateRoot, else nothing);import_tokensis now computed fromcode_linesin the facts struct and moved into the same posting loop. checkpoint()runs once per chunk on the calling thread (it isFnMut, so it cannot leak into the parallel map) and once per test in the in-order pass, so cancellation still aborts before any context is returned.
Delta evidence. parallel_context_build_matches_the_in_line_build spans 1,465 tests across 5 files and 3 chunks, compares the parallel and on-worker in-line builds field by field, rebuilds five posting maps independently in test order, checks index order by pointer identity, and fails if either branch is not taken (an off-pool build must take the parallel branch). context_test_facts_fan_out_off_the_pool_and_stay_in_line_on_a_worker pins the #8756 guard on both sides, and the author reports both tests fail when context_tests_fan_out() is forced to false.
Non-blocking.
- Cancellation granularity is now one chunk of fact computation (≤512 tests, ~80 ms by the author's 160 µs/test figure) instead of one test. Nothing on this head asserts that bound; a deadline test over a >512-test index would pin it.
- The equivalence test compares against the new in-line build, not the pre-change serial loop; the independent oracle covers the posting maps, while per-test fact values are asserted by the same closure on both paths — which is exactly the thread-independence property claimed, but not a re-derivation of those values.
- The
evidence_context_tests"start" trace now begins aftercontext_tests_fan_out()and the referenceVecallocation, so that phase's measured span is marginally smaller (microseconds).
Limits. Static review plus the committed goldens and hosted check status; I ran no cargo build or test. The byte-identical output and the 3.3–3.9 s context-phase deltas are the author's measurements on their box.
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY
VERDICT: APPROVE d92f163
Reviewed head: d92f163
Repair of the source-review carrier only. The semantic review of this head is unchanged; this replaces a verdict-first comment whose first line carried narrative after the SHA, which the admission gate refused (run 43969903993, "source review attestation refused"), leaving the queue entry UNMERGEABLE.
The substantive review is review 5927006445 on this exact head: APPROVE, no blocking findings, three non-blocking notes (cancellation granularity per 512-test chunk, the equivalence test comparing against the new in-line build, and a marginally smaller measured span). Its one review thread is resolved. Hosted checks are green on this head: Rust gates, all four Rust test shards, shards verify, Admit PR Candidate, Ripr Rust Small Result.
What the head does: CompactGripContext::build computes each test's pure context facts in 512-test chunks on the rayon pool, then fills the posting maps and CompactTest list in original test order, so output and ripr check bytes are unchanged.
|
Disposition (campaign heartbeat 22:58Z): carrier repaired, dequeued and re-enqueued at position 48. The merge_queue run 43969903993 refused this entry at 22:27Z on Repair is the carrier only: one gate-clean review at the same exact head, first line Dequeued the unmergeable entry and re-enqueued through the native mutation; it is QUEUED at position 48. |
Summary
CompactGripContextconstruction computes each test's pure context facts (call names, assertion tokens, helper/target-affinity owner names, stripped import lines and tokens, file key, normalized path, module path, lowercase name) in chunks of 512, mapped over rayon when nested parallelism is allowed.file_value_scanssharing andCompactTestassembly then run serially in original test order, so everyBTreeMap/Vecis identical to the serial build.nested_parallelism_allowedguard (perf: share RelatedTestCandidateIndex memos across threads so per-probe classify can run in parallel (#8629 follow-up) #8756); its re-export fromanalysis::classifyis no longer#[cfg(test)]-only.Swarm / Source Boundary
dependency, or repo-ops development for
ripr-swarmsurface
Source-of-truth Links
Proposal: n/a
Spec: n/a
ADR: n/a
Plan item: n/a
Governing issue or accepted claim: #12947
Acceptance delta (one sentence): The cold related-test context build for ripr-swarm's 30,669 tests drops from about 9.3 s to 5.9 s (per-test loop about 4.8 s to 1.7 s) with byte-identical
ripr checkJSON; this does not by itself meet any #12947 ratchet.Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication):
perf/parallel-grip-contextStack parent or prerequisite PR (if any): none
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): n/a
Accepted winner and losing candidate disposition (when decided): n/a
A PR search for
CompactGripContext,evidence_context,related_tests contextandparallel grip contextfound no open PR parallelizing this loop. #14880, #14865, #13900, #12451 and #14169 touch nearby context/owner-pin code but make different claims.Scope
crates/ripr/src/analysis/test_grip_evidence/related_tests/context.rs: chunked parallel per-test facts, then the in-order pass; two new tests.crates/ripr/src/analysis/classify/mod.rs: un-gate thenested_parallelism_allowedre-export.changelog.d/12947-parallel-grip-context-tests.md.Scope Classification
This PR is scoped by:
Production delta:
Evidence/support delta:
parallel_context_build_matches_the_in_line_build: 1,465 tests across 5 files (crate root, module files,mod.rs, integration test; spans 3 chunks). It compares the full projection of the off-pool (parallel) build with the on-worker (in-line) build: every posting map, every per-test field, file-scan sharing andfunction_name_counts. It also checks the posting maps against an independent in-order rebuild from the retained per-test facts, checks index order, and checks that the fixture really fills the helper-owner, assertion, import, stem and crate-root maps.context_test_facts_fan_out_off_the_pool_and_stay_in_line_on_a_worker: theLAST_CONTEXT_TESTS_FAN_OUTwitness isSome(true)off-pool andSome(false)insidepool.install.Single acceptance criterion:
ripr checkbytes, less cold context time.Non-goals:
shared_index_tables,target_affinity_owner_calls, etc.) or the seam pass. No change to warm behavior beyond the small 424-test context.Support-tier Impact
Claim/proof notes:
Policy Impact
Ledger or exception notes:
Proof
Base is
origin/main290e385 (this branch's merge base). Fix is this branch.evidence_context(30,669 tests) msOn every cold run the context phase is about 3.3 to 3.9 s shorter. Wall time is noisy on a shared box (cold deltas -8.6, -0.6 and -6.0 s). A warm run builds only the 424-test diff context, so warm gains are within noise. The warm main-evidence phase (
evidence_for_seams_progress, 216 seams) was 888/835 ms base and 867/949 ms fix, which is within noise.All 10 outputs (base and fix, cold 1-3 and warm 1-2) pass
cmpand are identical, 517,061 bytes each.Result, failures, or skipped proof:
test_index % 4096 == 0→test_index.is_multiple_of(4096), which is equivalent). Full workspace tests were not run locally; hosted CI owns them.Claim Boundary
What may be claimed: on this subject and box, the cold related-test context build is about 3.5 s faster, with identical output. Not claimed: any #12947 ratchet being met, a warm-loop improvement, or a stable wall-time delta.
Rollback
Revert the single commit. The change is local to context construction and needs no data migration.
Spec-Test-Code Traceability
parallel_context_build_matches_the_in_line_build,context_test_facts_fan_out_off_the_pool_and_stay_in_line_on_a_worker, existingowned_deadline_stops_context_test_loops_without_completing_contextCompactGripContext::build,context_tests_fan_outStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Thread-local review: the per-test facts read only the index and the context's tables.
MASK_MEMOand similar memos are pure caches.QUALIFIED_HELPER_CLEAN_COUNTis a#[cfg(test)]counter, and its test calls the helper directly. The cancellation-token thread-local is read only bycheckpoint(), which stays on the calling thread. By inspection, the per-test fact functions read neither the committed-source overlay nor the filesystem, and the A/B outputs are byte-identical.probe_read_traceis a diagnostic and is not active during context construction.Gates
cargo fmt --checkcargo xtask precommit(includes on-diff clippy forripr)Generated by Claude Code