Coding agents burn a surprising share of their token budget re-discovering things they already looked at. Grep for a symbol, read the file. Grep for its callers, read those files. Trace what breaks if you change it — grep, read, repeat. Every round-trip reloads source the model then has to re-read, and the structural questions ("what's the transitive blast radius of this function?") are the ones agents most often skip because doing them by hand is tedious.
CGraph takes a different path. It parses a repository once into a deterministic knowledge graph and keeps it resident in a per-project daemon, so where is this defined, who calls it, and what breaks if I change it become single millisecond-scale queries that return file:line instead of a wall of text.
The fair question is whether that actually pays off. In June we ran CGraph against two baselines: Graphify, an existing Python code-graph tool, and the thing agents actually do today — grep + read. Here is what we measured, how we measured it, and where the wins don't hold.
The setup
- Date: 2026-06-11
- Machine: Apple Silicon (arm64), macOS
- Build: CGraph
main@7d5503d, compiled in Debug (unoptimized) - Corpus: CGraph's own repository — 141 detected source files, a graph of ~960 nodes after full dedup
- Scripts:
benchmark_one_shot.pyandbenchmark_daemon_query.py, both in the repo
This is a self-run benchmark: CGraph, measured by its authors, on its own repository, in a Debug build. We're publishing the methodology and the scripts so you can reproduce it — and because a Debug build means the native numbers below are, if anything, conservative. Read the caveats at the end before you quote any single figure.
CGraph vs Graphify
Both tools turn a codebase into a graph. CGraph is native C++20; Graphify is a Python CLI. Across build and query, the gap is large:
| Measurement | CGraph (native) | Graphify (Python) | Speedup |
|---|---|---|---|
| Full build, this repo | 0.42 s | 83.2 s | ~198x |
| One-shot build, synthetic fixture (median of 3) | 0.019 s | 0.23 s | 12x |
| Warm query round-trip (median of 20) | 10.6 ms | 167 ms | 15.8x |
Three things to read carefully here:
- The full-build comparison is deliberately conservative in Graphify's favor. CGraph's 0.42 s is the entire pipeline — extract, merge, resolve, dedup, community detection, and every export. Graphify's 83.2 s is
update --no-cluster, which skips clustering. CGraph did strictly more work and still finished ~198x sooner. - The query gap is architectural, not just language. CGraph keeps the graph resident in memory behind a Unix socket, so a query is one round-trip into RAM. Graphify has no daemon — every query reloads
graph.jsonfrom disk first. - CGraph's daemon also keeps itself current. Gitignore-aware file watching folds edits in within seconds, incremental state re-persists in the background, and the graph survives restarts. Graphify only rebuilds on demand.
Token cost vs grep and read
Speed is nice, but the number that hits an agent's bill is tokens. So we ran four representative navigation tasks against the CGraph repo and measured the exact bytes a model would ingest (at ~4 chars/token) against two grep strategies:
- grep-efficient — a best-case disciplined agent: targeted greps, then narrow 100–200-line windowed reads. Assumes it already knows which file and line range to open.
- grep-typical — common behavior: grep, then read the whole matched file(s).
| Task | CGraph (tok / calls) | grep-eff (tok / calls) | grep-typ (tok / calls) |
|---|---|---|---|
| A. Find a definition | 114 / 1 | 1,192 / 2 | 5,960 / 2 |
| B. List callers | 259 / 1 | 190 / 1 | 4,322 / 3 |
| C. Blast radius (transitive) | 216 / 1 | 379 / 2 | 3,311 / 4 |
| D. Context bundle to edit (budget 4000) | 3,377 / 1 | 1,914 / 1 | 8,780 / 1 |
| Total | 3,966 / 4 | 3,675 / 6 | 22,373 / 10 |
Against realistic agent behavior, CGraph uses ~82% fewer tokens and 60% fewer round-trips. Against a perfectly disciplined grep agent it's roughly even on raw tokens (−8%) while still using 33% fewer round-trips.
Where grep still wins
We don't think the honest story is "CGraph beats grep." It's "CGraph beats what agents actually do, and complements grep":
- Task B (list callers) is where grep stays competitive — raw grep lines are already a compact caller list. CGraph's edge there is ranking and structure, not size.
- Task D (context bundle) shows
graph_context's trade-off: it spends budget on ranked neighbor snippets. If you already know the exact edit site, one targeted read is cheaper. The "efficient" grep path also assumed knowledge (thatpack_contextlives near line 380 ofdaemon_ops.cpp) that an agent usually spends tokens to acquire. - Task C (transitive blast radius) is the standout — a direction-aware, depth-ranked answer in a single call. The grep equivalent is a multi-round manual trace agents frequently skip, so in practice the real comparison is often "216 tokens" vs "the analysis never got done."
The caveats that matter
The token figures use a ~4 chars/token estimate, not a real tokenizer — trust the ratios more than the absolute counts. CGraph only indexes code structure: string literals, comments, config values, and un-extracted file types still need grep. And freshness lags edits by a few seconds (watch cadence plus debounce). CGraph complements grep; it does not replace it.
Try it yourself
Everything above is scripted and reproducible from a clone of the repo:
# full build on this repo vs Graphify (clustering skipped)
time build/default/src/cli/cgraph --root . --out /tmp/cgraph-bench-out
time graphify update . --no-cluster
# scripted comparisons
python3 scripts/benchmark_one_shot.py --native build/default/src/cli/cgraph
python3 scripts/benchmark_daemon_query.py --graphd build/default/src/daemon/graphd \
--client build/default/src/client/cgraph-client --root .
Bottom line
Against Graphify, CGraph is faster at everything both tools do (12–198x on builds, 15.8x on warm queries) and adds liveness Graphify doesn't have. Against the grep-and-read loop agents run today, it saves ~82% of the tokens and most of the round-trips — and turns transitive impact analysis from "tedious, usually skipped" into a single query. Grep is still the right tool for content search. For structure, a resident graph is hard to beat.
CGraph is open source and free to fork — read the code on GitHub.