Skip to content

perf(facts): prefetch helper-credit body parses on the pool and memoize the macro scan (#12947) - #14916

Merged
EffortlessSteven merged 2 commits into
mainfrom
perf/test-helper-credit
Nov 17, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
perf/test-helper-credit

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The index_test_helper_credit phase parsed test and helper bodies one at a time on the analysis thread. These were the rust: a helper that takes a closure parameter and asserts without ever invoking it still gives its assertion to the calling test as the oracle #9997 call-making-closure check for each admitted plain helper call, the invoked callback parameters and closure positions for callback helpers, and each helper's parser oracles. In a diff run, the first index (the admission core) paid for all of them serially. The cold review-stage workspace index (seam_inventory via check_stub_routes) runs with no run memo scope, so it paid for all of them again. The same-file assertion-macro scan re-parsed, in every index build, every test file that holds macro_rules. The gdb samples (persistent session, 2 s interrupts, release build with debug info) inside the phase were all parse_clean_source_file under passes_call_making_closure_uncached, invoked_callback_params_uncached, parser_oracles_for_function_uncached and local_macro_calls.
  • The pure per-call products are now split from the stateful HelperGate fold. A prefetch walks the same parse-free admission as the fold (admitted_test_module / admitted_helper, now shared by both). It computes the scope's misses in batches on the rayon pool through a new run_memo::memoize_many_with, using exactly the keys of the fold's memoized calls. The fold does not change and still owns every decision. The HelperGate is still asked only about helpers the fold asks about.
  • The helper pass and the macro pass each enter a run memo scope of their own. A caller's scope is shared. A caller without a scope gets the prefetch, and its products are dropped when the pass ends. When the caller is a pool worker, the prefetch is skipped (the batch would run serially there).
  • local_macro_calls is memoized per run (Product::LocalMacroCalls).

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Proposal:
Spec:
ADR:
Plan item:
Governing issue or accepted claim: #12947
Acceptance delta (one sentence): On ripr-swarm at 1e6f55b, the index_test_helper_credit phase of ripr check drops from about 3.9 s to 2.0 s per warm check and from 7.7 s to 3.9 s per cold check, and the JSON output stays byte-identical.

Candidate Relationships

Candidate branch (GitHub PR head is authoritative after publication): perf/test-helper-credit
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

I searched for test_helper_credit, HelperGate, credit_same_file_assertion_helpers, credit_same_file_assertion_macros, is_assertion_helper, helper-credit, prefetch, local_macro_calls and memoize_many_with. No open PR implements this claim. #13741 (merged) added the per-run memo that this builds on.

Scope

  • analysis/facts/test_helpers.rs: the prefetch, the shared admission helpers and the pass-level memo scope.
  • analysis/facts/test_helpers/assertion_macros.rs: the memoized macro scan and the pass-level memo scope.
  • analysis/syntax/run_memo.rs: memoize_many_with, MemoQuery and active(). memoize_many now delegates to memoize_many_with. Adds Product::LocalMacroCalls.
  • analysis/syntax/{ra.rs, ra/closure_callbacks.rs, local_assertion_macros.rs}: batch twins (*_many) that use the serial calls' memo keys.
  • analysis/syntax/nesting.rs: a test-only nesting_parse_calls() reader.

Scope Classification

  • One architectural seam

Production delta:

  • Performance only. The helper-credit phase computes the same pure syntax products ahead of its serial fold on the rayon pool, and memoizes the macro scan per run. Credit decisions are unchanged.

Evidence/support delta:

  • facts::test_helpers::tests::prefetch adds an equivalence test and a deterministic work-count test.

Single acceptance criterion:

  • The phase is cheaper and the output is byte-identical.

Non-goals:

  • Parallelizing the HelperGate fold itself. Forward-target products, which stay serial and are rare. ItemBindings::read and the #[path= scan, which another thread owns.

Support-tier Impact

  • none

Claim/proof notes:

  • No output, schema or vocabulary change.

Policy Impact

  • none

Ledger or exception notes:

  • One #[allow(clippy::too_many_arguments, reason = ...)] on admitted_helper. It mirrors the existing one on same_file_forward_target, and too_many_arguments is not a guarded lint.

Proof

cargo xtask precommit                      # exit 0 (selected: clippy -p ripr --all-targets, clippy -p xtask --all-targets, policy, diff checks)
cargo test -p ripr --lib -- analysis::facts analysis::syntax   # 883 passed, 0 failed
cargo test -p ripr --lib -- prefetch::     # 2 passed
# A/B: release builds (debug=1, strip=false) of origin/main c9425be1fe vs this change,
# subject: detached ripr-swarm at 1e6f55b3e9, `check --base HEAD~1 --format json`,
# RIPR_REPO_EXPOSURE_LATENCY_TRACE=1, separate RIPR_CACHE_DIR per binary, fresh cache per cold run

Result, failures, or skipped proof:

run base wall (s) fix wall (s) base phase (ms, per index) fix phase (ms, per index)
warm 1 27.64 26.03 3750 (2866/843/41) 2004 (1277/702/25)
warm 2 28.54 25.50 4248 (3304/903/41) 1981 (1270/667/44)
warm 3 27.50 25.74 3734 (2804/873/57) 2038 (1292/719/27)
cold 1 71.59 66.02 7444 (2899/939/41/3565) 4126 (1446/805/26/1849)
cold 2 69.55 67.20 7893 (2960/999/43/3891) 3591 (1260/708/26/1597)
  • Warm mean: the phase went from 3911 ms to 2008 ms (-1.9 s), and wall time from 27.9 s to 25.8 s (-2.1 s).
  • Cold mean: the phase went from 7669 ms to 3859 ms (-3.8 s), and wall time from 70.6 s to 66.6 s (-4.0 s).
  • cmp: all 11 JSON outputs (fix prime, warm ×3, cold ×2, plus the base runs) are byte-identical to the base cold reference.
  • Equivalence test: prefetched_credit_equals_the_fold_alone builds one fixture twice, once with the fold alone (without_prefetch) and once prefetched. The fixture covers every fold path: a plain assert_eq! helper, an invoked-callback helper, the rust: a helper that takes a closure parameter and asserts without ever invoking it still gives its assertion to the calling test as the oracle #9997 withheld closure, a forwarded closure to a same-file invoker, an unresolved forward (named limit), and an assertion macro. The test first asserts premises for each path, then asserts that the test facts and forwarded_callback_limits are equal.
  • Work-count test: prefetch_leaves_the_fold_no_parse_of_its_own checks clean parses made by the serial fold itself. The fold alone makes exactly 5. After the prefetch it makes 0, and the credit is unchanged.
  • Negative experiments, both run and then reverted:
    • Shifting the oracle prefetch key (discriminator: *start_line + 1) made the work-count test fail (left: 2, right: 0).
    • Storing a negated passes_call_making_closure result in the batch made both tests fail; the equivalence test showed the plain and withheld credit flipping.
  • Gaps:
    • The A/B binaries predate a doc-comment rewording and a #[cfg(test)] saturating_sub, which were made afterwards. The production code is otherwise identical to the A/B build.
    • The workspace-wide cargo test was not run locally; hosted CI covers it.
    • About 1.3 s of the admission-core phase remains: the serial fold, memo hashing, and the gate/admission walk, which now runs twice.

Claim Boundary

  • May claim: the helper-credit index phase is cheaper on warm and cold diff checks of this subject, with byte-identical JSON.
  • Must not claim: any analysis or classification change, or a general speedup on other repositories beyond what this subject measured.

Rollback

Revert the squash commit. There is no schema, cache-format or policy state involved.

Spec-Test-Code Traceability

  • Spec: n/a (performance only)
  • Tests: crates/ripr/src/analysis/facts/test_helpers/tests/prefetch.rs
  • Code: crates/ripr/src/analysis/facts/test_helpers.rs, crates/ripr/src/analysis/syntax/run_memo.rs
  • Golden outputs: unchanged
  • Metrics: the A/B above
  • ADR/learning: n/a

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. (none)
  • New generated, dependency, process-spawn, or network surfaces are allowlisted with owner and reason. (none)
  • Errors are reported with actionable context.
  • Public JSON/schema changes are documented. (none)

Gates

  • cargo fmt --check (via precommit)
  • cargo xtask precommit
  • Workspace-wide check/test/clippy/doc/package: left to hosted CI

Generated by Claude Code


Devin Review

…ze the macro scan (#12947)

The `index_test_helper_credit` index phase parsed test and helper bodies one
at a time on the analysis thread: the #9997 call-making-closure check per
admitted plain helper call, the invoked callback parameters and closure
positions for callback helpers, and each helper's parser oracles. The first
index of a diff run (the admission core) paid for all of them serially, and
the review-stage workspace index, built with no run memo scope, paid again.
The same-file assertion-macro scan re-parsed every test file holding
`macro_rules` in every index build.

- Split the pure per-call syntax products from the stateful HelperGate fold:
  a prefetch walks the same parse-free admission (`admitted_test_module`,
  `admitted_helper`, shared with the fold) and computes the scope's misses
  in batches on the rayon pool through a new `run_memo::memoize_many_with`,
  under exactly the keys the fold's memoized calls use. The fold is
  unchanged and still owns every decision and the HelperGate order.
- The helper and macro passes enter a run memo scope of their own; a caller
  scope is shared, and a caller with none gets the prefetch and drops it at
  the end of the pass. Pool-worker callers skip the prefetch.
- Memoize `local_macro_calls` per run (`Product::LocalMacroCalls`).

On ripr-swarm at 1e6f55b (216-seam diff), the phase falls from about
3.9 s to 2.0 s per warm check and 7.7 s to 3.9 s per cold check; JSON output
is byte-identical cold and warm.

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 56 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: beadbc89-6924-4323-89ff-beed3ef9c6c9
Commits

Reviewing files that changed from the base of the PR and between 6d5ca5e and 9c4ff36.

Files selected for processing: 11

  • changelog.d/12947-prefetch-helper-credit-parses.md
  • crates/ripr/src/analysis/facts/test_helpers.rs
  • crates/ripr/src/analysis/facts/test_helpers/assertion_macros.rs
  • crates/ripr/src/analysis/facts/test_helpers/tests.rs
  • crates/ripr/src/analysis/facts/test_helpers/tests/prefetch.rs
  • crates/ripr/src/analysis/syntax/local_assertion_macros.rs
  • crates/ripr/src/analysis/syntax/mod.rs
  • crates/ripr/src/analysis/syntax/nesting.rs
  • crates/ripr/src/analysis/syntax/ra.rs
  • crates/ripr/src/analysis/syntax/ra/closure_callbacks.rs
  • crates/ripr/src/analysis/syntax/run_memo.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 optimizes the helper-credit index pass by prefetching test and helper bodies on the Rayon thread pool ahead of its serial fold, and memoizes the same-file assertion-macro scan within a run to prevent redundant serial parsing. It introduces MemoQuery and memoize_many_with to support batch memoization of queries with discriminators. The review feedback suggests simplifying the run closure and missing_queries collection in run_memo.rs to accept and collect MemoQuery by value rather than by reference, since MemoQuery implements Copy, which avoids double-indirection and unnecessary heap allocations.

@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 found 2 potential issues.

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: 47cdfbe. A fresh reviewer who did not write the change reviewed it read-only and found no material defect.

Keys and products. Each *_many twin uses exactly the key and the *_uncached compute of its serial memo call:

  • (0, helper, test text) for the closure checks;
  • (0, "", helper text) for invoked params;
  • (start_line, "", text) for oracles.

Product::LocalMacroCalls is new. Every product is pure in its key inputs: it parses the text and takes no config, index, overlay or cancellation state. So computing on scope-less pool threads is answer-neutral. memoize_many_with keeps input order and deduplication, and never holds the memo RefCell while compute runs.

Admission. admitted_test_module and admitted_helper are line-for-line moves of the old inline checks, with order and short-circuit preserved. The prefetch warms a superset of the fold's reads. The HelperGate fold and its order are unchanged.

Memo scope. The per-pass scope drops at function exit. The outermost scope clears, and a nested scope only decrements. MemoStats feeds only the diagnostic cost trace.

Tests. The production parse_clean_source_file counter brackets only the serial fold. prefetch_leaves_the_fold_no_parse_of_its_own failed 2 vs 0 under a shifted oracle key. Under a negated closure result, prefetched_credit_equals_the_fold_alone showed credit flipping.

Bot threads. All four are answered and resolved:

  • Devin's extra oracle parses for withheld callbacks are a disclosed superset cost, already included in the measured win.
  • Devin's macro-memo reuse witness and Gemini's two by-value simplifications are optional. They will be carried on the next push.

Proof

  • cargo xtask precommit exits 0.
  • 883 analysis::facts / analysis::syntax lib tests pass.
  • JSON cmp is identical on 11 runs.
  • The phase drops from 3.9 s to 2.0 s warm and from 7.7 s to 3.9 s cold. Wall time drops from 27.9 s to 25.8 s warm.
  • Not run locally: the full workspace suite. Hosted CI covers it.

Generated by Claude Code

…cy scan stays clean (#12947)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UNUoLWvJLNTjPAkUKhsj5V

@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

Exact head 9c4ff36. Delta from the previously attested head 47cdfbe is only the rename of the test switch without_prefetch to with_fold_alone in test_helpers.rs and test_helpers/tests/prefetch.rs, so the network-policy scan no longer matches a fetch-call literal. No production behavior changed.

Local proof on this head: cargo xtask check-network-policy passes, cargo check -p ripr --lib --tests exits 0, cargo fmt --check is clean. Earlier independent review, byte-identical JSON A/B and work-count evidence carry forward unchanged.


Generated by Claude Code

@EffortlessSteven

Copy link
Copy Markdown
Member Author

Disposition: admitted to the merge queue (position 42) at exact head 9c4ff3657f.

Guard check against the campaign merge conditions:

  • Current substantive review: SOURCE_REVIEW_READY at 9c4ff3657fe8b2f1f17294f2484f85de277b740b (exact head).
  • Required checks: 21/21 completed, zero failures, zero pending.
  • Review threads: 0 unresolved.
  • Mergeable: MERGEABLE / CLEAN; merge-ready label present.
  • Inside the recorded campaign packet; no release, settings, credential or queue change.

Enqueued through the native merge-queue route with the exact head as expectedHeadOid. The queue owns the landing; this is not a merge claim.

@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 9c4ff36 — no blocking findings on this head.

What I checked (source, at this head)

Memo keys match the serial calls exactly, which is the correctness hinge of the whole prefetch:

  • passes_call_making_closure_many / closure_argument_positions_many build MemoQuery { discriminator: 0, extra: helper_name, source: test_text }, matching the serial memoize_with(product, 0, helper, test_text, ..).
  • invoked_callback_params_many delegates to memoize_many (discriminator 0, no extra), matching memoize(product, 0, helper_text, ..).
  • parser_oracles_for_functions_many uses discriminator: start_line, extra: "", matching memoize(product, function_start_line, function_text, ..).

The prefetch is a superset of the fold's serial reads on the paths it claims:

  • Non-plain helper -> invoked_callback_params(helper.body) is warmed for every callback helper.
  • Exactly one invoked parameter -> closure_argument_positions(test.body, call.name) is warmed; the fold reads it under the same condition.
  • Plain helper -> passes_call_making_closure(test.body, call.name) is warmed.
  • Helper oracles -> warmed for every plain helper and every single-invoked-parameter callback helper, which covers every point where the fold reaches parser_oracles_for_function(&helper.body, ..) (the invoked.len() != 1 and not-reached cases continue first). Forward-target oracles are deliberately left to the fold; that is a missing warm-up, never a wrong value.

admitted_test_module / admitted_helper are a faithful extraction of the inline checks (local use, cfg, module identity, calls_directly, test_shadows, bound names, span overlap), and the fold's decisions are unchanged. HelperGate is a pure per-file cache (production_files + ManifestInventory), so asking it during the prefetch cannot change the fold's answers.

memoize_many_with preserves the old memoize_many contract: same key function, duplicate keys deduped through seen, misses fanned out only when the caller is not a pool worker, hits/misses counted as before, and the final recall-or-compute pass returns exactly the serial results in order. Product is part of the key, so no cross-product collision is possible with LocalMacroCalls.

local_macro_calls is pure in its source text (LocalMacroCall holds names, line numbers and arm text only), so memoizing it under the file text is sound; the pool-worker branch keeps the previous par_iter fan-out.

The fold-alone parse arithmetic is internally consistent with the work-count fixture: 2 parses for the plain test (passes_call_making_closure + oracles) and 3 for the callback test (invoked params + closure positions + oracles) = the asserted 5, and 0 after the prefetch.

Hosted evidence at this head: Admit PR Candidate, Ripr Rust Small on GitHub Hosted / Rust gates, all four Rust tests shard N of 4, Rust test shards verify and Ripr Rust Small Result are SUCCESS; no unresolved review threads.

Non-blocking note

The PR says "The HelperGate is still asked only about helpers the fold asks about." The walk is the same, but the fold skips a repeated call name once credited_helpers holds it, while the prefetch admits every call. Because the gate is an idempotent per-file cache, this changes no answer and no output; it is only an extra cached lookup. The doc comment on admitted_helper could say so.

Limits

No local build or benchmark (read-only beat). The speed claim (3.9 s -> 2.0 s warm, 7.7 s -> 3.9 s cold) is the author's A/B measurement and I did not reproduce it; I verified only the equivalence and key structures it depends on. A/B binaries predate two cosmetic edits by the author's own account, which does not affect production 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.

SOURCE_REVIEW_READY

Reviewed head: 9c4ff36

Carrier only. This repeats, at the same exact head, the substantive approval in review 5929880442 (no blocking findings; one non-blocking doc note that the prefetch asks the idempotent per-file HelperGate about repeated call names, which changes no answer). That review's first line carries narrative after the SHA, so this comment keeps a gate-readable attestation as the latest review on the head. Hosted checks on this head are green and no review threads are unresolved.


Generated by Claude Code

Merged via the queue into main with commit 261427e Nov 17, 2026
21 checks passed
@EffortlessSteven
EffortlessSteven deleted the perf/test-helper-credit branch November 17, 2026 04:18
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