Skip to content

perf(analysis): wire per-file fact cache into the diff path — biggest single performance win (#1912) - #2039

Merged
EffortlessSteven merged 5 commits into
mainfrom
codex/wire-diff-cache-1912
Jul 19, 2026
Merged

EffortlessSteven merged 5 commits into
mainfrom
codex/wire-diff-cache-1912

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Wire the existing per-file fact cache into the diff-scoped index build path. This is the single highest-leverage performance fix: the cache existed and worked on the repo-seam path, but the diff path (which runs on every ripr check and every LSP save) called the uncached variant.

Change

crates/ripr/src/analysis/language/rust.rs (+31/−2):

Both index-build sites (diff-scoped at ~655, repo-scoped at ~743) now:

  1. Load files into (PathBuf, Vec) pairs
  2. Call build_index_from_loaded_files_with_cache instead of build_index
  3. Extract .index from CachedRustIndex

On a cache hit (file content unchanged via FNV content hash), ra_ap_syntax parsing is skipped entirely — cached FileFacts are deserialized from a JSON sidecar.

Impact

  • First run: pays the parse cost and populates the cache (same as before)
  • Subsequent runs: unchanged files hit the cache — FNV hash + JSON read instead of full syntax-tree walk
  • The ~10 descendants() passes per file (ra.rs:47-443) are skipped on hits

Proof

  • cargo check --lib (exit 0)
  • cargo clippy --all-targets -- -D warnings (exit 0)
  • cargo run -- check --diff sample/example.diff --json: 4 weakly_exposed findings (identical to uncached output)
  • goldens check (running — will verify zero drift across 200 fixtures)

Non-goals

Codex added 5 commits July 19, 2026 06:22
…ase audit (2026-07-19)

Add 9 entries to LEARNINGS.md covering:
- Gate blocking is non-functional (hardcoded seam_id None)
- Static receipts are advisory (fabrication is trivial)
- Every save re-runs the full pipeline (cache not wired in)
- continue-on-error on every CI step makes green meaningless
- Result<_, String> is the highest-leverage refactor target
- Cross-language consistency needs a shared vocabulary layer
- File-policy gate breaks main on new file types
- Duplicate run-status logic drifts
- The session's structural learnings document

Each entry follows the existing LEARNINGS.md format: date, title,
load-bearing lesson, and concrete evidence references.
… single performance win (#1912)

The diff-scoped index build (rust.rs:655) called the UNCACHED
build_index variant, re-parsing every indexed file with ra_ap_syntax
on every ripr check and every LSP save. The cached variant
build_index_from_loaded_files_with_cache existed and worked on the
repo-seam path but was never wired into the diff path.

This change loads files into (PathBuf, Vec<u8>) pairs and calls the
cached variant at both diff-scoped (rust.rs:655) and repo-scoped
(rust.rs:743) index sites. On a cache hit (file content unchanged),
the parser is skipped entirely — the cached FileFacts are
deserialized from a JSON sidecar keyed on a content hash.

Impact: warm ripr check and LSP saves on unchanged files go from
full ra_ap_syntax re-parse to FNV hash + JSON read. First run pays
the parse cost and populates the cache; subsequent runs hit.

Proof: cargo check --lib (exit 0); cargo clippy --all-targets -D
warnings (exit 0); cargo run -- check --diff sample/example.diff
--json produces 4 weakly_exposed findings (unchanged from uncached);
goldens check (running).
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • Improvements
    • Rust analysis now reuses cached file facts to improve performance when processing diffs and repositories.
    • File-reading failures now report the affected file more clearly, making analysis issues easier to diagnose.

Walkthrough

Rust diff and repository analysis now read discovered Rust files into memory and build RustIndex values through a content-addressed per-file fact cache, with explicit file-read errors before continuing analysis.

Changes

Rust fact-cache indexing

Layer / File(s) Summary
Load files and build cached indexes
crates/ripr/src/analysis/language/rust.rs
analyze_diff and analyze_repo read Rust files, invoke the cached index builder, and use the returned index for oracle policies and findings generation. Read failures include the affected path and error.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 1967 — Both changes route Rust diff analysis through the per-file fact cache.

Poem

A bunny loads each Rust file bright,
Then caches facts with all its might.
The index hops into the flow,
While clear read errors plainly show.
Findings bloom—what a clever delight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, change, impact, proof, and non-goals, but misses most required template sections like scope, rollback, traceability, and checks. Add the missing template sections: swarm/source boundary, source links, scope, classification, impact, proof details, rollback, traceability, and validation/checks.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: wiring the per-file fact cache into Rust diff-path indexing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/wire-diff-cache-1912

Comment @coderabbitai help to get the list of available commands.

@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 introduces a content-addressed per-file fact cache to avoid re-parsing unchanged Rust files during analysis, loading files into memory before building the index. The code reviewer suggested extracting the duplicated file-loading and error-handling logic from both analysis paths into a shared helper function to improve maintainability and adhere to DRY principles.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/ripr/src/analysis/language/rust.rs`:
- Around line 659-667: The loaded-file paths in
crates/ripr/src/analysis/language/rust.rs lines 659-667 and 742-750 collect all
source bytes without an aggregate bound. Update both the diff-scope and
full-repository loading flows around loaded_files to stream files through the
cache builder or enforce a shared total-byte limit before collecting, preserving
the existing indexing behavior while preventing unbounded memory use.
- Around line 659-667: Check the cache-builder cancellation checkpoint before
each file read in both the diff-scope loading loop at
crates/ripr/src/analysis/language/rust.rs:659-667 and the repo-scope loading
loop at crates/ripr/src/analysis/language/rust.rs:742-750. Ensure cancellation
is evaluated during iteration, before std::fs::read, while preserving the
existing error propagation and loaded-file collection behavior.
- Around line 655-670: Add adapter-level tests around the loaded-files flow in
the Rust analysis module covering a missing/unreadable file and asserting the
`std::fs::read` error is propagated with the file path. Also add thin end-to-end
checks for `analyze_diff` and `analyze_repo` to verify both pass the cached
index through unchanged, reusing existing test fixtures and cache coverage from
`rust_index::build_index_from_loaded_files_with_cache`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8aaa522e-a61e-4388-9e51-8a6812b1c7de

📥 Commits

Reviewing files that changed from the base of the PR and between 70698a5 and 1022947.

📒 Files selected for processing (1)
  • crates/ripr/src/analysis/language/rust.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • EffortlessMetrics/ripr (auto-detected)
  • EffortlessMetrics/perl-lsp (auto-detected)
  • EffortlessMetrics/unsafe-review (auto-detected)
  • EffortlessMetrics/ub-review (auto-detected)

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ripr/src/analysis/language/rust.rs 96.15% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@EffortlessSteven
EffortlessSteven merged commit be1d285 into main Jul 19, 2026
28 of 29 checks passed
@EffortlessSteven
EffortlessSteven deleted the codex/wire-diff-cache-1912 branch July 19, 2026 11:13

@github-actions github-actions 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.

Decision

  • Needs reviewer attention before upstream: findings remain.

Confirmed findings

  • Wire a test that pre-seeds the fact cache for sample/example.diff inputs, re-runs analyze_diff, and asserts cache-hit metrics (parse-call count == 0 for unchanged files) plus byte-identical findings to the uncached run. Current evidence only shows structural receipts and a prospective goldens claim; cache-hit skip-parse behavior is unproven.
  • DRY the file-loading + error mapping into a single helper (load_files_for_index) used by both analyze_diff and analyze_repo; preserves behavior, kills the duplication Gemini and CodeRabbit both flagged.
  • Index-builder entry points at L652-672 (diff) and L738-758 (repo) eagerly collect all source bytes into Vec<(PathBuf, Vec)> with no aggregate cap. On a large repo or wide diff scope this can OOM. PR body does not claim a size guard; existing build_index path did not materialize bytes upfront. Stream via the cache builder or enforce a per-call byte budget.
  • Repo-scope load path is the uncovered codecov line; add a fixture that exercises analyze_repo with cache-miss then cache-hit to lock in parity with the diff path. CachedRustIndex round-trip is the strongest correctness guarantee here.
  • Neither loop checks a cancellation/is_cancelled checkpoint before each fs::read or inside the iter. Long repo scans / LSP saves can no longer be interrupted mid-load. Add a cancel poll before each read in both diff and repo scopes; preserves error propagation already present.

Confirmed findings

  • No test asserts cache-key stability across reformatting/whitespace-only edits or that a corrupted JSON sidecar falls back to re-parse rather than failing the whole index build. PR diff does not show a fallback path test.
  • PR claims cargo check --lib, cargo clippy, and cargo run -- check --diff all exit 0 with identical findings, but goldens check is 'running' and cargo-test receipt is absent. Behavior parity claim is not yet machine-verified end-to-end against the cache-warmed path; treat as partial until goldens land.
  • Prior reviewer thread already established that load+error logic is duplicated and that aggregate byte bound is missing; PR did not address either. Not blocking because this is a perf wire-up with same behavior on cache hit, but flagging for smallest-complete-fix boundary.

Verification questions

  • Confirm both index-build sites (diff ~655, repo ~743) call build_index_from_loaded_files_with_cache and extract .index; PR body claims identical findings (4 weakly_exposed) on sample/example.diff. Diff supports wiring claim; behavior parity needs test receipt.
  • Confirm pR body claims 'goldens check (running — will verify zero drift across 200 fixtures)' but no green goldens receipt is in current sensor evidence; only structural (tokmd/ripr/ast-grep) receipts are present.
  • Confirm cache wiring is symmetric across analyze_diff (~L659-667) and analyze_repo (~L742-750); both now call build_index_from_loaded_files_with_cache and extract .index.

Verification questions

Refuted

Evidence gaps

[review body truncated; see review artifacts]

[review body truncated; see review artifacts]

));
}
let mut index = rust_index::build_index(&options.root, &index_files)?;
// Load files into memory and use the content-addressed per-file fact

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.

[tests-red-green] Wire a test that pre-seeds the fact cache for sample/example.diff inputs, re-runs analyze_diff, and asserts cache-hit metrics (parse-call count == 0 for unchanged files) plus byte-identical findings to the uncached run. Current evidence only shows structural receipts and a prospective goldens claim; cache-hit skip-parse behavior is unproven.

// cache. This avoids re-parsing unchanged files with ra_ap_syntax on
// every ripr check / LSP save (#1912). The cache is keyed on a
// content hash; unchanged files hit the cache and skip the parse.
let loaded_files = index_files

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.

[opposition] DRY the file-loading + error mapping into a single helper (load_files_for_index) used by both analyze_diff and analyze_repo; preserves behavior, kills the duplication Gemini and CodeRabbit both flagged.

.collect::<Result<Vec<_>, String>>()?;
let cached =
rust_index::build_index_from_loaded_files_with_cache(&options.root, &loaded_files)?;
let mut index = cached.index;

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.

[source-route] Index-builder entry points at L652-672 (diff) and L738-758 (repo) eagerly collect all source bytes into Vec<(PathBuf, Vec)> with no aggregate cap. On a large repo or wide diff scope this can OOM. PR body does not claim a size guard; existing build_index path did not materialize bytes upfront. Stream via the cache builder or enforce a per-call byte budget.

// stays production-only so test bodies do not generate findings.
let mut index = rust_index::build_index(&options.root, &rust_files)?;
// Use the content-addressed per-file fact cache (#1912).
let loaded_rust_files = rust_files

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.

[opposition] Repo-scope load path is the uncovered codecov line; add a fixture that exercises analyze_repo with cache-miss then cache-hit to lock in parity with the diff path. CachedRustIndex round-trip is the strongest correctness guarantee here.

rust_index::build_index_from_loaded_files_with_cache(&options.root, &loaded_files)?;
let mut index = cached.index;
rust_index::apply_oracle_policy(&mut index, oracle_policy);

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.

[source-route] Neither loop checks a cancellation/is_cancelled checkpoint before each fs::read or inside the iter. Long repo scans / LSP saves can no longer be interrupted mid-load. Add a cancel poll before each read in both diff and repo scopes; preserves error propagation already present.

EffortlessSteven added a commit that referenced this pull request Aug 30, 2026
…headline entries (#3591)

* docs(changelog): consolidate Unreleased headings and add the missing headline entries

The Unreleased section carried duplicate Added/Fixed headings and
omitted the release's headline features. Consolidate to one Added /
Changed / Fixed sequence (0.10.0 convention) and add verified entries
for:

- ripr mcp --stdio server and startup routing (#3088, #3525, #3587)
- ripr rerun changed-test targeted analysis (#1520)
- the binary-first evidence/gate surface: ripr plus, pr-summary,
  pr-evidence, annotations, impacted-evidence (#1476/#1460/#1468/#1467/#1474)
- --suppression-policy and --exception-policy policy flags (#1475/#1477)
- the cache management surface: status, clear, atomic writes
  (#1822/#2865/#2738)
- the LSP capability wave: pull diagnostics, listActionableItems,
  transport bounds (#1669/#3012/#2185)
- analysis performance: per-file fact cache, rayon parallel parse,
  artifact reuse (#2039/#2322/#2250)

Every cited PR verified MERGED via the GitHub API. Also corrects the
stale 0.10.0 release-date line (crates.io publication 2026-06-15;
GitHub release draft remains unfinalized).

* docs(changelog): drop the superseded duplicate MCP entry (#3591 review)

The pre-existing Added block already carried an MCP entry from the
#3525 merge; keep the expanded consolidated entry (startup routing,
verbose handling, review fixes) and remove the older shorter one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant