Repository navigation
perf(index): release builder slack when an index is finalized (#5363) - #9576
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PrRRMBXfD85Xo2kQ9La4AV
|
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 58 minutes. View limit details
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a memory optimization to release spare capacity in the Rust fact index once building is finished. It implements a release_build_slack method that calls shrink_to_fit() on various vectors and strings within the index, and adds a corresponding test suite to verify the capacity reduction. The review feedback suggests expanding the spare_capacity test helper to include all the fields that are shrunk in release_build_slack, ensuring the test is fully robust and covers all optimized collections.
…vectors, cover every shrunk field in the test (#5363) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PrRRMBXfD85Xo2kQ9La4AV
|
Review of record, head 9f9932b Angles: (1) correctness and edge cases, (2) tests and regressions, (3) spec/contract and cancellation. An independent reviewer inspected 667fe9d. Its findings, plus the Gemini and Devin threads, were applied in 9f9932b:
Measured: cold index live memory 427.6 → 374.3 MB. Peak RSS on the cold pilot is unchanged within noise (about 1.2 GB), because the peak sits in
Generated by Claude Code |
There was a problem hiding this comment.
Decision
- Needs one verification check before upstream.
Verification questions
- Confirm checkpoint stride 4096 with
if visited % N == 0still observes cancellation at index 0, so a one-fact index aborts on first check.
Refuted
- Box::from(slice) allocation-failure path in this PR; refuted because: PR diff does not touch Box::from or any slice-to-box conversion; this objection is out of scope and not raised by diff or seeded thread.
- Exact zero capacity is allocator-sensitive, but the project explicitly accepts this as a regression signal for the crate's std global allocator.
- Exact-capacity assertions could produce allocator-dependent failures unrelated to the release behavior.; refuted because: This limitation is acknowledged in the seeded review; with the crate's std global allocator, shrink_to_fit is intended to yield the requested exact length, and the test is designed to flag any platform contract violation.
- The exact-capacity assertion is an invalid test because allocator behavior can retain capacity.; refuted because: The repository uses the standard global allocator; the test intentionally treats retained capacity as a failure of the documented shrink contract.
Parked follow-ups
- The test helper is intentionally coupled to the production shrink inventory, making omission detection effective but requiring future buffer additions to update both sites.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
|
Verification answer for the github-actions review: yes. Each of the three loops checks Generated by Claude Code |
|
Generated by Claude Code |
|
Independent static review of current 9f9932b found two regression-proof gaps, not a demonstrated production failure. Please keep repairs with this existing owner.
Retain existing hosted qualification while preparing the bounded repair; review the successor independently and requalify only applicable changed scope. Keep the measured claim at one-build live heap427.6->374.3MB, not peak RSS or speed. No duplicate writer or benchmark campaign requested. |
… each checkpoint and field (#5363) The cancellation test now drives the pass with a small stride and expires each interior checkpoint in turn, asserting later work stays untouched. The capacity test populates every nested collection and names the field that was not released. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PrRRMBXfD85Xo2kQ9La4AV
|
Both regression-proof gaps from the static review are repaired on the same branch (test commit 9f9827e, merged with current main as 4b68ace).
An independent review of this head is running. Once it returns I'll re-apply Generated by Claude Code |
|
Independent source review at4b68ace7911f158a8ef21a726d4ffbc1b7eb2feb materially closes the two proof gaps raised in6337517394. The successor adds a direct-pass phase-sensitive cancellation oracle and populated, per-label capacity fixtures; the owner's four site-specific mutation receipts remain four-site evidence, not an exhaustive any-site claim. The injected stride2 test is legitimate bounded later-boundary coverage: production release_build_slack directly delegates to the same release_build_slack_in_strides algorithm with SLACK_CHECKPOINT_STRIDE=4096, using the same visited % stride checks. A new4096-sized campaign is not required merely to duplicate that algorithm. The remaining capacity==len marker is a portability fragility, not an established production defect or blocker to this bounded repair. No blocking finding in this delta review. This is source review, not independently executed tests. Current-head ub-review39762274423 and wheel39762274476 were still running; skipped workflows do not establish qualification. Please preserve the existing validation/owner flow and reconcile exact-head required gates before merge. |
|
Next existing-owner gate after source review6338586471: please bind integration validation to current merge head4b68ace7911f158a8ef21a726d4ffbc1b7eb2feb, or document exact-tree equivalence and relevant base coverage from the retained local receipt. The reported precommit receipt names pre-merge9f9827e5; it must not silently stand in for current composition. Wheel39762274476 succeeded while CI/security workflows skipped and ub-review remained running at observation. Once current integration and independent review prerequisites are satisfied, use the existing required-check admission flow once and retain its actual checkout identity. Reconcile work already running before triggering anything; no duplicate campaign is requested. |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- crates/ripr/src/analysis/facts/index_tests.rs:708 —
spare_by_fieldadds the file's own file_returns/file_literals/spare under file.* and a per-edge declaration, butfacts.probe_shapesis reserved yet the membership helper doesn't includeself.files.values()entries' own per-file positions — fine, but a deleted membership shrink on the four flat vectors currently shows up only via thebefore/afterstrict-less rule, not a field-specific mutation. Add a focused mutation: comment out the membership shrink in the test, expectfunction_orderorfunction_positionsto appear inunreleased.
Refuted
- The optimization crosses a broader abstraction boundary or requires generalizing all index storage compaction.; refuted because: Rejected: the helper is private to RustIndex and directly enumerates only growable fields on this concrete index; no shared abstraction or unrelated caller is changed.
- shrink_to_fit exact-capacity assertions depend on allocator behavior and are not a valid test.; refuted because: Refuted: crate forbids unsafe_code so only the std global allocator is in use; the test intentionally treats retained capacity as a contract violation, which is the desired regression signal. Author's stance in seeded thread is consistent with this lane's read.
Parked follow-ups
- ast-grep structural pass detected no sibling shrink_to_fit/insertion routes outside the changed files within the changed surfaces; this lane did not re-run ast-grep, relying on the cached receipt (ok). Public callers of finalize are not broadened by this diff.
- The change adds one compaction pass whose reallocation cost is not measured; this is bounded performance risk rather than a demonstrated correctness defect.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
…drop them (#5363) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PrRRMBXfD85Xo2kQ9La4AV
|
Head is now 6f25b54 (test commit plus a merge of current main). Changes since 4b68ace, test file only: an independent review found that the per-element capacity labels ( Validation binding: Generated by Claude Code |
|
Independent bounded delta review at6f25b54bd2e92165a0aa34753819e973e3da8274 finds no blocker. Test commit4bf7f4a adds function/file ReturnFact fixtures and pins47 capacity labels; production index source is unchanged, and the subsequent main merge leaves both index files identical to4bf7. This extends the prior source review rather than restarting it. Required admission is already active:39768558670 admitted expected head6f25b54, with hosted Rust job119790292006 running. Preserve that single campaign, reconcile any current-head ub-review findings and verify its actual checkout plus terminal required result before merge. No additional label reapplication or dispatch is needed. Current local/test claims remain separate from hosted qualification. |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- release_build_slack is private and only called from finalize; the shrink-to-fit guarantee is implicit. A doc comment on RustIndex::finalize stating that a finalized index holds no spare capacity would protect future callers who build an index without going through finalize.
Verification questions
- Confirm exact-capacity assertions in spare_by_field depend on std::alloc::Global returning len==cap after shrink_to_fit; this is the crate's only allocator (forbid(unsafe_code)) so it is the platform contract, but a future custom alloc would silently fail the test rather than flag the shrink omission.
- Confirm release_build_slack is not called from any other code path; if a future caller builds a RustIndex without invoking finalize, the new slack-free contract is silently broken. Documented only in PR body, not in a doc comment on finalize or on RustIndex.
- Confirm checkpoint ordering across the three loops: if a deadline expires between the function-loop's last checkpoint and the test-loop's first checkpoint, work past the boundary is observed only by the final finalize checkpoint (test count=13). The added test pins this to expire_at=12, which is the first interior checkpoint, so the later-boundary path is not independently exercised at production stride.
- Confirm per-site mutation receipts are documented but not exhaustive across the 47 labelled fields; fixture-pin (47 labels + before-empty check) and per-field strict-less rule give strong but not any-site proof. Not a blocker; surfaced for visibility.
Refuted
- Box::from(slice) allocation-failure path could regress inside release_build_slack.; refuted because: PR diff does not touch Box::from or any slice-to-box conversion; release_build_slack only invokes Vec/String::shrink_to_fit, which return unit. Out of scope and not raised by diff or seeded thread.
- A sibling path also releases build slack and was missed by this PR; refuted because: Grep across crates/ripr/src/analysis/facts/ for shrink_to_fit, compact, trim, and capacity()-len shows only the new release_build_slack implementation; no other helper or call site exists in this module.
- release_build_slack belongs at a higher abstraction (free fn / trait) so other index backends can reuse it; refuted because: Helper is private to RustIndex and enumerates only fields on this concrete index. The PR is bounded to one production behavior; no shared abstraction or unrelated caller is changed. Smaller complete fix stays inside the impl block.
- Exact-capacity shrink_to_fit assertions are an invalid test because allocators may retain capacity; refuted because: crate forbids unsafe_code and uses only the std global allocator; the test is designed to flag any platform where the documented shrink_to_fit contract stops holding, which is the regression signal the author wants. Devin/gemini concerns were resolved-checked in the seeded thread.
Evidence gaps
- ripr sensor failed (exit 2) and cargo-test is late; no fresh execution evidence on current head 6f25b54, but seeded owner receipts show passing cargo test -p ripr --lib on the test commit and green precommit (comments 10:20, 11:10).
- Model proof intent was rejected by deterministic validation.
|
Independent reconciliation of later review5613515752 against current6f25b54bd2e92165a0aa34753819e973e3da8274: the asserted between-loop cancellation hole is not present. Each function/test/file loop checks at visited=0 before processing its first nonempty fact, and the stride2 test iterates checkpoints across all three passes. The earlier count13 test is not the only discriminator. Current per-label capacity checks require decrease rather than universal exact-zero allocation; retain the separate cancellation-marker portability caveat already documented. The remaining finalize-doc location suggestion is limited documentation: slack release is documented on the private helper but could also be mentioned on finalize. No new production blocker is established by that suggestion or by unexecuted exhaustive per-site mutants. Relevant source: index.rs646-800 and index_tests.rs878-1051 at this exact head. Current hosted qualification is still separate and must finish. Its eventual success must not erase the separately failed sensor/model-proof attempt; retain each outcome on its own subject. Source clearance6339501271 remains applicable. |
Summary
RustIndex::finalizenow shrinks the arenas, each fact's vectors and strings, and the per-file vectors once the index is complete (a finished index never grows).clone()is 254.8 MB plus 57.8 MB of source, so most of the remaining difference is Arc-shared call text (about 30 MB, 530k allocations) and non-cloned state, not slack.pilot --mode readypeak RSS was 1,237 MB on this build against 1,202 to 1,292 MB on earlier main runs, so one run does not show a peak change. The peak is insideevidence_for_seams(see the cold-pilot-memory findings); this change lowers what the index holds during it.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Proposal: none
Spec: none (no behavior change)
ADR: none
Plan item: none
Governing issue or accepted claim: #5363, #7220
Acceptance delta (one sentence): A finalized index holds no spare vector or string capacity.
Scope Classification
Production delta:
analysis/facts/index.rs(RustIndex::finalizecallsrelease_build_slack).Evidence/support delta: test
finishing_an_index_releases_the_spare_capacity_the_builders_left; changelog fragment.Single acceptance criterion: after
finalize, no counted fact vector or string has capacity above its length.Non-goals: call-text sharing (about 30 MB), probe-shape field widths (88 B each, 72 MB), the evidence-phase peak.
Support-tier Impact
Policy Impact
Proof
Mutation check: with the
release_build_slackcall commented out, the new test fails. The existing pointer-identity tests (moved_large_payload_has_one_backing_through_both_ordered_views) still pass.Claim Boundary
May claim: the finished cold index holds about 53 MB less live heap on this repository. Must not claim: a peak-RSS reduction, or a change in index build time (not separately measured; the added work is one pass of
shrink_to_fitover the facts).Rollback
Revert the squash; no format or schema change.
Spec-Test-Code Traceability
analysis/facts/index.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.Generated by Claude Code