Skip to content

perf(session): prefilter and parallelize session search - #25

Merged
urmzd merged 1 commit into
mainfrom
perf/session-search-prefilter
Oct 27, 2026
Merged

urmzd merged 1 commit into
mainfrom
perf/session-search-prefilter

Conversation

@urmzd

@urmzd urmzd commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Summary

agentspec session search parsed every candidate transcript one at a time before matching. This change makes full scans 3-8x faster.

  • Raw-text prefilter: for literal queries, a transcript is parsed only if its raw file contains every ASCII word (3+ chars) of the query. Regex queries, unreadable files, and non-ASCII words fall through to a full parse, so the check cannot drop a real match.
  • Parallel scan: candidates are scanned in rayon chunks and folded in order, so results stay newest first and --limit / --scan still stop early. Prefiltered sessions do not count toward --scan.
  • Load by path: SessionMetaIR records source_path (not serialized), and a new SessionAdapter::load_from_meta parses it directly instead of re-walking storage by ID.
  • JSON report gains a prefiltered count.

Benchmark (535 sessions, warm cache, release build)

Query Before After
no-hit literal 2.75s 0.35s
cargo 2.46s 0.68s
"rate limit" --role user 2.39s 0.91s
--regex 'cargo\s+build' 2.83s 0.53s
--tool-used Bash 2.51s 0.53s

Result sets matched the old binary on all six benchmark queries, except one bug fix: three Gemini files sharing session ID 4e24b246… were previously all loaded from the first file found. They now load from their own files.

Test plan

  • cargo fmt --check, cargo clippy --all-targets -D warnings
  • cargo test (158 passing, 2 new prefilter tests)
  • Old vs new result diff on 6 queries

Search parsed every candidate transcript sequentially before matching.
Now it:

- skips transcripts whose raw bytes lack any ASCII word of a literal
  query (regex queries are not prefiltered)
- scans candidates in parallel chunks with rayon, keeping newest-first
  order and early stop on --limit/--scan
- loads sessions from the path recorded at listing time instead of
  re-walking storage by ID

Full scans over 535 sessions drop from ~2.5s to 0.35-0.9s. Loading by
path also fixes Gemini sessions that share an ID returning the same
file repeatedly. The JSON report gains a `prefiltered` count.
@urmzd
urmzd merged commit 58f4146 into main Oct 27, 2026
6 checks passed
@urmzd
urmzd deleted the perf/session-search-prefilter branch October 27, 2026 02:51
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