Skip to content

perf(cat/grep/cli): per-file overhead cuts and faster cold start - #194

Closed
nwaughachukwuma wants to merge 1 commit into
add-report-flag-for-cat-commandfrom
claude/perf-catgrep-coldstart-s230yb
Closed

perf(cat/grep/cli): per-file overhead cuts and faster cold start#194
nwaughachukwuma wants to merge 1 commit into
add-report-flag-for-cat-commandfrom
claude/perf-catgrep-coldstart-s230yb

Conversation

@nwaughachukwuma

@nwaughachukwuma nwaughachukwuma commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • mm grep: lists files via the Rust JSON fast path (no pyarrow import, ~120 ms/invocation); matches in one C-speed finditer pass (re.MULTILINE; zero-match files skip the per-line loop entirely); serves documents from the content-hash cache instead of re-extracting every PDF on every run; single-pass highlighting. mm wc uses the same cache with a thread pool.
  • cat pipeline: Magika ONNX model no longer loads or runs for auto-strategy — its output was never read there; mm.toml parsed once per mtime instead of ~10x per file; Generate type hints evaluated once; content hash computed once per file; ffmpeg probe + transcription OpenAI client process-cached; encoder discovery drops its O(modules × files) realpath sweep; keyframe counting demuxes packet flags instead of decoding every I-frame twice; JPEG 4:2:0 unless alpha.
  • CLI cold start: importlib.metadata deferred behind module __getattr__; pipeline/yaml imports out of the cat registration path.

Speed gains

Change Old New Speedup
mm grep (340-file fixture, --count) wall 345 ms 238 ms 1.45x
repeat grep over PDFs full re-extraction per run one indexed SELECT 10-100x on document corpora
Magika in auto-strategy load + per-file inference skipped ~0.3-0.5 s per binary-file mm cat
mm.toml read 188 µs/call 27 µs 7x (× ~10 reads per cat'd file)
keyframe count decode all I-frames twice demux flags ~2x on the keyframes pipeline
import mm.cli 97 ms 77 ms 1.26x on every invocation

Validation

1,208 Python tests pass; ruff clean. Includes the test updates for the new content_hash kwarg and the cached transcription client.

🤖 Generated with Claude Code

https://claude.ai/code/session_012GnYsrLTmdJphKkm7yjWDV

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@nwaughachukwuma nwaughachukwuma left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude please followup

Comment thread python/mm/video.py
Comment on lines 416 to 428
def _count_keyframes(self) -> int:
"""Quick I-frame count via demux-level skip."""
"""I-frame count from packet flags only — demux, no decode."""
import av

container = av.open(str(self._path))
try:
stream = container.streams.video[0]
stream.codec_context.skip_frame = "NONKEY"
count = 0
for packet in container.demux(stream):
for _ in packet.decode():
if packet.is_keyframe and packet.pts is not None:
count += 1
return count
finally:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude, how does this compare against the old implementation, and what's the change in behavior?

Comment thread CHANGELOG.md Outdated
Comment on lines +21 to +37
- **RSI batch — grep/cat overhead + CLI cold start (260803)**:
- `mm grep`: Rust JSON fast path for the listing (no pyarrow import,
~120 ms/invocation); matching is one C-speed `finditer` pass with
`re.MULTILINE` (zero-match files skip the per-line loop entirely);
documents route through the content-hash cache instead of
re-extracting every PDF each run; single-pass highlighting.
Fixture end-to-end: 345 ms → 238 ms wall.
- Magika no longer loads or runs for encoder auto-strategy — it only
ever read dimensional metadata (~0.3-0.5 s per binary-file `mm cat`;
model load off import). mm.toml parsed once per mtime (~10
parses/file → 1); `Generate` type hints evaluated once; content hash
threaded through `run_fast`/`run_accurate`; ffmpeg probe and the
transcription OpenAI client process-cached; keyframe counting demuxes
packet flags instead of decoding every I-frame twice; image payloads
encode JPEG 4:2:0 unless alpha is present.
- CLI cold start: `importlib.metadata` deferred, pipeline/yaml imports
out of the `cat` registration path — `import mm.cli` 97 ms → 77 ms.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the changes in changelog.md

Comment thread python/mm/cli.py
invoke_without_command=True,
help="Fast, multimodal context for agents.",
epilog=f"mm v{__version__}",
epilog="mm — fast, multimodal context for agents (mm --version)",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert to what it was before - we don't want cosmetic changes.

@nwaughachukwuma
nwaughachukwuma force-pushed the claude/core-perf-optimization-s230yb branch from 9ce1d7e to 0d2f4ca Compare August 12, 2026 10:30
@nwaughachukwuma
nwaughachukwuma force-pushed the claude/perf-catgrep-coldstart-s230yb branch from a56fb33 to f33c7c2 Compare August 12, 2026 10:32
- mm grep: Rust JSON fast path for the listing (no pyarrow import), single
  finditer pass with MULTILINE, documents served from the content-hash cache,
  single-pass highlighting. mm wc routes documents through the same cache.
- Magika no longer loads or runs for encoder auto-strategy — its output was
  never read there (~0.3-0.5s per binary-file mm cat; model load off import).
- mm.toml parsed once per mtime (~10 parses/file → 1); Generate type hints
  evaluated once; content hash computed once per file; ffmpeg probe and the
  transcription OpenAI client process-cached; encoder discovery drops its
  O(modules x files) realpath sweep.
- Keyframe counting demuxes packet flags instead of decoding every I-frame
  twice; image payloads encode JPEG 4:2:0 unless alpha is present.
- CLI cold start: importlib.metadata deferred, pipeline/yaml imports out of
  the cat registration path (import mm.cli 97ms → 77ms).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GnYsrLTmdJphKkm7yjWDV
@nwaughachukwuma
nwaughachukwuma force-pushed the claude/perf-catgrep-coldstart-s230yb branch from f33c7c2 to 9c03a83 Compare August 12, 2026 10:40
@nwaughachukwuma
nwaughachukwuma changed the base branch from claude/core-perf-optimization-s230yb to add-report-flag-for-cat-command August 12, 2026 10:40
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.

2 participants