perf(store): O(1) ensure_metadata, staleness-gated upserts, parallel batch extraction - #192
Closed
nwaughachukwuma wants to merge 1 commit into
Closed
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
…batch extraction - ensure_metadata: single-file Rust scan_one + extract_metadata_one instead of a full parent-directory scan + Arrow round-trip per file (hit twice per mm cat file). 96ms → 18ms per fresh file at 340 siblings; sibling scaling removed entirely. - upsert_files: snapshot (modified, size, content_hash) before upserting and re-extract only new/changed rows. Warm Context.save() 212ms → 8ms (26x), cold save 1220ms → 175ms (7x) on the 340-file fixture. - New Scanner.extract_metadata_batch: rayon-parallel extraction with the GIL released, one FFI crossing instead of N (3.2-17x vs the serial loop); O(1) path index replaces the per-call linear entry scan (O(n²) across a save). - Benchmarks: Criterion scan_single_vs_dir_walk group; pytest-benchmarks for warm/cold save, ensure_metadata, and batch-vs-serial / scan_one-vs-walk A/B pairs. Numbers in benchmarks/mm-bench-260803.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012GnYsrLTmdJphKkm7yjWDV
nwaughachukwuma
force-pushed
the
claude/core-perf-optimization-s230yb
branch
from
August 3, 2026 12:49
efb91ce to
9ce1d7e
Compare
This was referenced Aug 3, 2026
nwaughachukwuma
commented
Aug 3, 2026
nwaughachukwuma
left a comment
Collaborator
Author
There was a problem hiding this comment.
@claude, please follow-up
Comment on lines
+104
to
+130
| import json as json_mod | ||
|
|
||
| from mm._mm import Scanner | ||
|
|
||
| scanner = Scanner(str(scan_root), None, no_ignore=no_ignore) | ||
| scanner.scan() | ||
| exts = [e.strip() for e in ext.split(",")] if ext else [] | ||
| rows = json_mod.loads( | ||
| scanner.to_json_fast(kind=kind, ext=exts[0] if len(exts) == 1 else None) | ||
| ) | ||
| for row in rows: | ||
| if row["path"].startswith("."): | ||
| continue | ||
| if len(exts) > 1 and row["ext"] not in exts: | ||
| continue | ||
| resolved = str((_directory.resolve() / f.path).resolve()) | ||
| resolved = str(scan_root / row["path"]) | ||
| if resolved not in seen_paths: | ||
| seen_paths.add(resolved) | ||
| files_to_search.append(f) | ||
| files_to_search.append( | ||
| FileEntry( | ||
| row=dict( | ||
| path=row["path"], | ||
| kind=row["kind"], | ||
| is_binary=row["is_binary"], | ||
| ) | ||
| ) | ||
| ) |
Collaborator
Author
There was a problem hiding this comment.
@claude, I hope you benchmarked this replacement and the gain is both significant, stable and reliable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Base PR of the RSI batch, stacked on #181. Storage write path only (12 files); the query-plan and grep/cat/cold-start work land as two child PRs into this branch. Hashing-policy changes are excluded from the batch.
ensure_metadatais O(1): single-file Rustscan_one+extract_metadata_onereplaces a full parent-directoryScannerwalk + Arrow round-trip per file (it ran twice permm catfile).upsert_filesstaleness gate: snapshots(modified, size, content_hash)and re-extracts only new/changed rows.Scanner.extract_metadata_batch: rayon-parallel extraction with the GIL released, one FFI crossing instead of N; O(1) path index replaces the per-call linear entry scan (O(n²) across a save).Speed gains
End-to-end (4-core VM; 340-file fixture: 300 × 200-line .py + 40 PNGs; baseline = #181 head):
Context.save()warmContext.save()coldPer-change A/B (new vs replaced path, same build):
scan_singlevs parent-dir walk (Criterion, 50 siblings)scan_onevsScanner+ Arrow (1,000 siblings)Documented tradeoff (surfaced by the A/B benches):
extract_metadata_batchhas ~3-4 ms fixed rayon dispatch per call, so trees of near-empty files favor the serial loop in isolation; it's a per-save constant and end-to-end saves still win.Validation
TestRecordingFileenv failures fail identically on the base commit).scan_single_vs_dir_walk; pytest-benchmarks for warm/cold save,ensure_metadata, and the batch/scan A/B pairs. Full tables inbenchmarks/mm-bench-260803.md.cargo bench -p mm-core --bench metadata_extract -- scan_single_vs_dir_walk uv run pytest tests/python/test_benchmark.py -m slow -k "save or ensure_metadata or ab_" --benchmark-only🤖 Generated with Claude Code
https://claude.ai/code/session_012GnYsrLTmdJphKkm7yjWDV