Repository navigation
Conversation
12458
force-pushed
the
benchmark-suite
branch
from
November 23, 2026 15:12
6e44b51 to
767372a
Compare
12458
force-pushed
the
benchmark-suite
branch
6 times, most recently
from
November 28, 2026 09:48
2a4f5bc to
8d2daff
Compare
12458
marked this pull request as ready for review
November 28, 2026 10:50
12458
marked this pull request as draft
November 28, 2026 15:49
--perf prints its timing table for a person to read. A benchmark harness comparing two builds wants the same numbers in a form it can parse. --perf-json FILE writes the statistics as JSON, keyed by metric name, with durations in milliseconds. It implies --perf, so the table is still printed. The lore, commits-only and branch modes return before the statistics are written, so the flag is refused there, and its directory is checked before indexing rather than after the run.
--perf only timed vector generation, so an index run without vectors reported nothing. Record the phases of the tree and range pipelines: loading the processed-file set, commit metadata, the file pipeline, database optimization and the call-edge index. Inside the pipeline, record each file's analyzer setup and analysis, and each batch insert. The per-file and per-batch metrics run on worker threads, so their totals are CPU time summed across threads, not wall time. Together they show where a run spends its time: on the full v7.3.6 kernel tree, inserts take about 110 s of the 114 s file pipeline on the two default --db-threads, while analysis needs about 54 s across the workers. Without --perf a measurement costs two clock reads and an atomic load, next to milliseconds of analysis per file.
Analyzer changes need a quicker, quieter measurement than indexing the kernel. cargo bench --bench analyzer times the Tree-sitter analyzer on real sources from a pinned Linux tree (v7.3.6 from linux-stable): - parse_only: Tree-sitter alone, the floor under analysis, so a regression can be placed in the grammar or in semcode's extraction. Parsing is about a quarter of analysis time, an eighth for headers. - analyze_file: seven large, call-heavy files across subsystems, a big header and a Rust driver file. - corpus: a fixed sample of ~200 files spread over the whole tree, so typical files and per-file overhead count too. Each file's analysis is checked to find something before it is timed. Sources are read from the tree's committed blobs, so edited, untracked or generated files cannot change what is measured, and are not vendored: the kernel is GPL-2.0. Without a tree the benchmarks skip; a tree that is not at the tag, or has local changes, is refused. bench/bench.py setup, added later in this series, fetches it.
An index is built once and read many times, so the read path is what a benchmark should exercise most, with the calls users actually make. Those go to the kernel's core API far more often than to its leaf functions, and they are the expensive ones: find_callers on per_cpu_ptr takes 8 s through the MCP server, on a uniformly sampled leaf function a few milliseconds. A uniform sample would make reads look ~100x cheaper than they are. bench/workload.rs reads a full index of the pinned tree and writes bench/workload.jsonl: 94 calls to find_function, find_callers, find_calls, find_type and grep_functions, drawn from fan-in and fan-out tiers (>=1000, 100-999, 20-99 callers), the most used types, names with many definitions and the longest bodies, with a small light share so per-call overhead stays visible. Sampling is weighted reservoir sampling on a salted hash of each name, so the same index gives the same workload; the file is committed with the tag and regenerated only when the tag moves. An index holding more than one commit is refused. Each call lists what its answer must contain. A lookup that finds nothing answers in 80 ms against 1.6 s for a heavy one, so without the check a build that broke lookups would look faster. semcode echoes the query even into an answer that found nothing, so the check is on something only a result prints: a caller, a callee or a file path from a result row, or for a heavy find_callers a printed caller count of at least a quarter of the fan-in. It is an example, so it builds against the library, and lives next to the workload it writes. test = false keeps cargo test from linking it.
bench/bench.py builds the semcode checkout it is in and times it on the
pinned kernel tree:
bench/bench.py setup # shallow clone of v7.3.6, history to v7.3
bench/bench.py run # read scenarios
bench/bench.py run -s index
To compare two versions, run it in each and compare the results; each
run records the commit it measured.
Read scenarios, the default, since an index is built once and read many
times:
mcp bench/workload.jsonl replayed through semcode-mcp with a
built-in stdio client: time to ready, a first and a warm
pass, and a pass with four requests in flight
mcp-dirty the same on a working copy with 20 edited files
mcp-behind the server started on a v7.3.5 index with the tree at
v7.3.6, catching up before it answers
mcp-aged the same on an index holding every commit of
v7.3.5..v7.3.6, history accumulated
cli one-shot semcode -q queries from bench/queries.txt
Index scenarios: subset (fs/ from empty), full (the whole tree from
empty) and update (a v7.3.5 index brought to v7.3.6 by a plain
semcode-index).
Every answer is checked, since a lookup that finds nothing returns
quickly. Each index scenario starts with an untimed run that warms the
page cache, records the phase breakdown with --perf-json, and fails if
the index has no functions. Indexes are built by each run, never kept.
The report gives mean and standard deviation per scenario, and per MCP
tool p50/p95/max latency and the slowest calls.
A first run on a laptop:
- A warm pass of the workload takes 68 s; p50 243 ms, p95 1.5 s, the
slowest find_callers 8.4 s.
- Four requests in flight take as long as one at a time, with p50
latency 1.7 s: the server answers requests one by one.
- The working-copy overlay costs ~15% on every call.
- After catching up from v7.3.5 (10 s), the server answers 3.7x slower
(254 s a pass), while mcp-aged, with far more history but built by
semcode-index, is not slower (73 s).
- Indexing the whole tree takes 127 s and 3.9 GiB; inserts take ~110 s
of the 114 s file pipeline on the two default --db-threads.
The script runs under uv and uses only the standard library.
How to set up and run the harness and the Criterion benchmarks, what each scenario measures, how answers are checked, how to regenerate the workload, and what to change when the kernel tag moves.
- build() takes the binaries' paths from cargo's artifact messages, so a build target (target/<triple>/release) no longer measures stale ones. - The update scenario fails if it leaves base.db's table counts unchanged, so an indexer that does nothing cannot pass as a speedup. - MCP peak RSS is reported as n/a where VmHWM cannot be read, not 0. - Phase timings are elapsed time summed across threads, not CPU time; say so in the report and in PerfStats::to_json(). - The Criterion corpus pins its extensions instead of following the indexer's defaults, which would change the sample under the same ID. - bench_workload requires the new bench feature: test = false did not stop cargo test building and linking it. - Note that workload.rs credits a caller with its first kernel definition, not the one that made the call.
The preflight checked only that the parent directory existed, so a --perf-json naming an existing directory ran the whole indexing pass, modifying the database, before failing with "Is a directory". Validate the path with ReportSink::prepare, as --result-json does, and write the statistics through the same sink so they are published atomically. PerfStats::write_json has no callers left.
- Start semcode-mcp with --max-concurrent-requests set to the widest pass. The server defaults to 2 and refuses calls beyond its limit with -32001, so the four-wide parallel pass failed. - Keep a reply's isError flag apart from its text, and match the server's miss messages only at the start of a line, so source text containing "error: " or "not found in database" is not a miss. - Check that a reused kernel checkout holds BASE and BASE..TAG, in setup and before a run needing it, and print the fetch that fixes it.
12458
force-pushed
the
benchmark-suite
branch
from
November 28, 2026 16:14
8d2daff to
5a302ee
Compare
This branch has not been deployed
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.
Adds benchmarks of semcode on a pinned Linux kernel tree (
v7.3.6from linux-stable, fetched from kernel.googlesource.com), so a change in the numbers is a change in semcode, not in the input. An index is built once and read many times, so reads come first.bench/bench.py(a uv script, stdlib only) builds the checkout it's in and times it. To compare two versions, run it in each and compare the results; each run records the commit it measured.mcp:bench/workload.jsonlreplayed throughsemcode-mcp: time to ready, a first and a warm pass, and a pass with 4 requests in flightmcp-dirty: the same on a working copy with 20 edited filesmcp-behind: the server started on a v7.3.5 index with the tree at v7.3.6mcp-aged: the same workload on an index holding every commit ofv7.3.5..v7.3.6cli: one-shotsemcode -qqueries-s index):subset(fs/),fullandupdate(v7.3.5 → v7.3.6).bench/workload.rsgenerates the committed workload: 94 calls tofind_function,find_callers,find_calls,find_typeandgrep_functions, weighted towards the kernel's most used names, since real queries go there and those calls cost the most.benches/analyzer.rs(Criterion):parse_only,analyze_file(7 large files) andcorpus(~200 files sampled across the tree).semcode-index --perf-json FILE, and phase timings in the tree and range pipelines; without--vectors,--perfused to report nothing. These are the only changes to semcode itself.Every answer is checked against something only a real result prints (a caller, a callee, a path from a result row, or a minimum caller count), because a lookup that finds nothing answers fast and semcode echoes the query even then. Each index scenario starts with an untimed run that warms the page cache, records the phase breakdown, and fails if the index has no functions.
Benchmarks
From earlier runs on a laptop, with the workload at 118–120 calls before it was trimmed to the five tools above:
mcpwarm passfind_callers per_cpu_ptr)mcp, 4 requests in flightmcp-dirtywarm passmcp-behindmcpmcp-agedwarm passclicallers kfree1.6 sfullindexupdatePoints to follow up:
mcp-aged, with far more history but built bysemcode-index, reads at normal speed, so the likely cause is the server's background catch-up skipping the optimization the CLI indexer runs. Not yet confirmed.mcpparallel pass measures it.--db-threads. Parsing is about a quarter of analysis time.kernel/bpf/verifier.c:11781to a function namedBTF_ID, a macro.Validation
On these commits:
cargo clippy --all-targets -- -D warnings(-j 2) or, forbench.py, ruff;cargo fmt --checkpasses.cargo bench --bench analyzer -- --testpasses.semcode-mcp, and answers that found nothing are rejected.bench/bench.py run -s all -r 1of this code ran every scenario with all checks passing:mcpwarm pass 61 s (p50 236 ms),mcp-behind257 s,mcp-aged74 s,fullindex 126 s,update9.4 s.cargo testpassed (632 tests) on an earlier version of this branch; it hasn't been rerun since, and these commits change semcode itself only in--perf-json's argument checks.