Repository navigation
perf(facts): prefetch helper-credit body parses on the pool and memoize the macro scan (#12947) - #14916
Conversation
…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
|
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 56 minutes. View limit details
|
There was a problem hiding this comment.
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.
EffortlessSteven
left a comment
There was a problem hiding this comment.
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 precommitexits 0.- 883
analysis::facts/analysis::syntaxlib tests pass. - JSON
cmpis 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
left a comment
There was a problem hiding this comment.
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
|
Disposition: admitted to the merge queue (position 42) at exact head Guard check against the campaign merge conditions:
Enqueued through the native merge-queue route with the exact head as |
EffortlessSteven
left a comment
There was a problem hiding this comment.
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_manybuildMemoQuery { discriminator: 0, extra: helper_name, source: test_text }, matching the serialmemoize_with(product, 0, helper, test_text, ..).invoked_callback_params_manydelegates tomemoize_many(discriminator 0, no extra), matchingmemoize(product, 0, helper_text, ..).parser_oracles_for_functions_manyusesdiscriminator: start_line, extra: "", matchingmemoize(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, ..)(theinvoked.len() != 1and not-reached casescontinuefirst). 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
left a comment
There was a problem hiding this comment.
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
Summary
index_test_helper_creditphase 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_inventoryviacheck_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 holdsmacro_rules. The gdb samples (persistent session, 2 s interrupts, release build with debug info) inside the phase were allparse_clean_source_fileunderpasses_call_making_closure_uncached,invoked_callback_params_uncached,parser_oracles_for_function_uncachedandlocal_macro_calls.HelperGatefold. 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 newrun_memo::memoize_many_with, using exactly the keys of the fold's memoized calls. The fold does not change and still owns every decision. TheHelperGateis still asked only about helpers the fold asks about.local_macro_callsis memoized per run (Product::LocalMacroCalls).Swarm / Source Boundary
ripr-swarmSource-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_creditphase ofripr checkdrops 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-creditStack 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_callsandmemoize_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,MemoQueryandactive().memoize_manynow delegates tomemoize_many_with. AddsProduct::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-onlynesting_parse_calls()reader.Scope Classification
Production delta:
Evidence/support delta:
facts::test_helpers::tests::prefetchadds an equivalence test and a deterministic work-count test.Single acceptance criterion:
Non-goals:
HelperGatefold itself. Forward-target products, which stay serial and are rare.ItemBindings::readand the#[path=scan, which another thread owns.Support-tier Impact
Claim/proof notes:
Policy Impact
Ledger or exception notes:
#[allow(clippy::too_many_arguments, reason = ...)]onadmitted_helper. It mirrors the existing one onsame_file_forward_target, andtoo_many_argumentsis not a guarded lint.Proof
Result, failures, or skipped proof:
cmp: all 11 JSON outputs (fix prime, warm ×3, cold ×2, plus the base runs) are byte-identical to the base cold reference.prefetched_credit_equals_the_fold_alonebuilds one fixture twice, once with the fold alone (without_prefetch) and once prefetched. The fixture covers every fold path: a plainassert_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 andforwarded_callback_limitsare equal.prefetch_leaves_the_fold_no_parse_of_its_ownchecks 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.discriminator: *start_line + 1) made the work-count test fail (left: 2, right: 0).passes_call_making_closureresult in the batch made both tests fail; the equivalence test showed theplainandwithheldcredit flipping.#[cfg(test)]saturating_sub, which were made afterwards. The production code is otherwise identical to the A/B build.cargo testwas not run locally; hosted CI covers it.Claim Boundary
Rollback
Revert the squash commit. There is no schema, cache-format or policy state involved.
Spec-Test-Code Traceability
crates/ripr/src/analysis/facts/test_helpers/tests/prefetch.rscrates/ripr/src/analysis/facts/test_helpers.rs,crates/ripr/src/analysis/syntax/run_memo.rsStatic 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.Gates
cargo fmt --check(via precommit)cargo xtask precommitGenerated by Claude Code