Skip to content

perf(evidence): build related-test context facts in parallel chunks (#12947) - #14892

Merged
EffortlessSteven merged 1 commit into
mainfrom
perf/parallel-grip-context
Nov 17, 2026
Merged

EffortlessSteven merged 1 commit into
mainfrom
perf/parallel-grip-context

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

  • CompactGripContext construction 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.
  • The posting-map inserts, file_value_scans sharing and CompactTest assembly then run serially in original test order, so every BTreeMap/Vec is identical to the serial build.
  • Cancellation/deadline is checked once per chunk (on the calling thread, before fan-out) and once per test in the in-order pass.
  • On a rayon worker the build stays in line, using the existing nested_parallelism_allowed guard (perf: share RelatedTestCandidateIndex memos across threads so per-probe classify can run in parallel (#8629 follow-up) #8756); its re-export from analysis::classify is no longer #[cfg(test)]-only.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge,
    dependency, or repo-ops development for ripr-swarm
  • repair or follow-up for a same-repo swarm PR
  • swarm-only CI, runner, routing, source-of-truth, or agent-operating
    surface
  • other swarm-scoped work:

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 check JSON; this does not by itself meet any #12947 ratchet.

Candidate Relationships

Candidate branch (GitHub PR head is authoritative after publication): perf/parallel-grip-context
Stack 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 context and parallel grip context found 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 the nested_parallelism_allowed re-export.
  • changelog.d/12947-parallel-grip-context-tests.md.

Scope Classification

This PR is scoped by:

  • One production behavior
  • One public contract
  • One architectural seam
  • Docs/spec/test-only evidence package
  • Other:

Production delta:

  • The per-test context loop fans out off the pool and runs in line on a pool worker. Output is unchanged.

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 and function_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: the LAST_CONTEXT_TESTS_FAN_OUT witness is Some(true) off-pool and Some(false) inside pool.install.

Single acceptance criterion:

  • Same context, same ripr check bytes, less cold context time.

Non-goals:

  • Parallelizing the earlier context phases (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

  • none

Claim/proof notes:

  • Performance only; no output or claim change.

Policy Impact

  • none

Ledger or exception notes:

  • n/a

Proof

cargo xtask precommit                                  # exit 0
<ripr lib test bin> related_tests::context::           # 15 passed, incl. owned_deadline_stops_context_test_loops_without_completing_context
<ripr lib test bin> test_grip_evidence::               # 647 passed
# negative: context_tests_fan_out() forced to `false`
#   -> context_test_facts_fan_out_off_the_pool_and_stay_in_line_on_a_worker FAILED (left (15, Some(false)), right (15, Some(true)))
#   -> parallel_context_build_matches_the_in_line_build FAILED ("an off-pool build must take the parallel branch")
# A/B on ripr-swarm 1e6f55b3e9: `ripr check --base HEAD~1 --format json`, RIPR_REPO_EXPOSURE_LATENCY_TRACE=1,
#   fresh RIPR_CACHE_DIR per cold run, warm runs reuse the cold-3 cache; release builds, 4-core shared box

Base is origin/main 290e385 (this branch's merge base). Fix is this branch.

run base wall s fix wall s base evidence_context (30,669 tests) ms fix ms base test loop ms fix ms
cold 1 91.8 83.2 9079 5856 4711 1769
cold 2 85.9 85.3 9176 5893 4814 1756
cold 3 89.5 83.5 9702 5818 5020 1622
warm 1 38.4 38.7 82 (424-test context) 45 51 16
warm 2 37.9 39.7 82 46 52 15

On 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 cmp and are identical, 517,061 bytes each.

Result, failures, or skipped proof:

  • The measured fix binary was built before a clippy-only edit (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

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • New non-Rust programming files are allowlisted with owner, surface, and reason.
  • New generated, dependency, process-spawn, or network surfaces are allowlisted with owner and reason.
  • Errors are reported with actionable context.
  • Public JSON/schema changes are documented.

Thread-local review: the per-test facts read only the index and the context's tables. MASK_MEMO and similar memos are pure caches. QUALIFIED_HELPER_CLEAN_COUNT is a #[cfg(test)] counter, and its test calls the helper directly. The cancellation-token thread-local is read only by checkpoint(), 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_trace is a diagnostic and is not active during context construction.

Gates

  • cargo fmt --check
  • cargo xtask precommit (includes on-diff clippy for ripr)
  • remaining workspace gates: hosted CI

Generated by Claude Code


Devin Review

…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
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 145 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: a2f4ddd7-696b-4519-a914-48e3ccc2440e
Commits

Reviewing files that changed from the base of the PR and between e403f8d and d92f163.

Files selected for processing: 3

  • changelog.d/12947-parallel-grip-context-tests.md
  • crates/ripr/src/analysis/classify/mod.rs
  • crates/ripr/src/analysis/test_grip_evidence/related_tests/context.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_build compares 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.

  1. On a pool worker, cancellation can now land up to one 512-test chunk later (about 80 ms). The PR body discloses this.
  2. The deadline test pins the stop count, not the position of each check.
  3. Gemini's is_multiple_of finding is answered on its thread: the method is stable since Rust 1.87, and the MSRV here is 1.95.

Proof:

  • cargo xtask precommit exits 0.
  • 647 test_grip_evidence:: lib tests pass.
  • JSON cmp is identical across 10 cold and warm runs.
  • Cold evidence_context drops 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 EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  • ContextTestFacts is derived only from index, the TestSummary, and whole-index tables built before the loop. The context's own Mutex/OnceLock caches (parsed_sources, owner_lookups, shared_grips, pin_syntax, ...) are fields of the not-yet-constructed CompactGripContext, 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, and nested_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_iter collected into Vec, which preserves chunk order, and chunk.iter().zip(chunk_facts) then posts in global test order. Every posting map, file_name_counts and tests are therefore built in the same order as the serial loop.
  • file_value_scans Arc sharing is preserved: the entry is created at the same point in struct construction (last field), so tests in one file still share one OnceLock.
  • The file-key branch is unchanged in substance (Stem, else CrateRoot, else nothing); import_tokens is now computed from code_lines in the facts struct and moved into the same posting loop.
  • checkpoint() runs once per chunk on the calling thread (it is FnMut, 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.

  1. 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.
  2. 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.
  3. The evidence_context_tests "start" trace now begins after context_tests_fan_out() and the reference Vec allocation, 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 EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@EffortlessSteven
EffortlessSteven removed this pull request from the merge queue due to a manual request Nov 16, 2026
@EffortlessSteven
EffortlessSteven added this pull request to the merge queue Nov 16, 2026
@EffortlessSteven

Copy link
Copy Markdown
Member Author

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 Admit PR Candidate: "source review attestation refused" — a current-head COMMENT was required whose first line is exactly SOURCE_REVIEW_READY/REVIEW_READY, or exactly VERDICT: APPROVE d92f1635f8202ba0d7ea21a89d45ca6871245fe8. The review already on this head (5927006445, 20:25Z) put narrative after the SHA on its first line, so the gate could not read it, and the entry sat UNMERGEABLE at position 2.

Repair is the carrier only: one gate-clean review at the same exact head, first line SOURCE_REVIEW_READY, second line the verdict, then a note that it repeats the existing substantive review. The semantic review is unchanged — APPROVE, no blocking findings, three non-blocking notes, one review thread resolved. Hosted checks are green on d92f163: Rust gates, four Rust test shards, shards verify, Admit PR Candidate, Ripr Rust Small Result.

Dequeued the unmergeable entry and re-enqueued through the native mutation; it is QUEUED at position 48.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
@EffortlessSteven
EffortlessSteven added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 3603ffa Nov 17, 2026
22 checks passed
@EffortlessSteven
EffortlessSteven deleted the perf/parallel-grip-context branch November 17, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants