Skip to content

perf(architecture): read codegraph's index directly instead of one probe per symbol - #47

Merged
inth3shadows merged 1 commit into
masterfrom
arch-direct-index-read
Sep 27, 2026
Merged

inth3shadows merged 1 commit into
masterfrom
arch-direct-index-read

Conversation

@inth3shadows

Copy link
Copy Markdown
Owner

Roadmap item: make --architecture (and --forbid) cheap enough to run on every commit.

Why: the scan spent nearly all its time starting one codegraph callees process per symbol: 48.7s on this repo, where codeshot's own work is ~0.4s.

What: on Node 22.5+, readIndexRows reads <path>/.codegraph/codegraph.db once via node:sqlite (read-only, no new dependency). It pulls every edge of codegraph's own callee kinds (calls/references/imports/instantiates/navigates, from its getCallees). fileEdgesFromIndexRows then derives each definition's answer using codegraph's own overload grouping (name + file + qualified name).

  • Enumeration stays on the CLI, so the symbol set and --max-symbols are unchanged.
  • Falls back to the CLI probes on Node 18/20, when there's no index at that path, on any read failure, or with CODESHOT_INDEX_READ=cli.
  • The read sees every edge, so it drops import-only callees exactly (the CLI's one-edge-per-callee JSON can't; see fix(architecture): stop the CLI probes fabricating and dropping edges #46).
  • --limit caps nothing on this path. On Node 22.5+, fork and npm codegraph now draw the same weights.

Proof by equality with the incumbent: with the import-only rule switched off, the direct read renders byte-identical diagrams to the CLI probes on: this repo (1 edge), the duplicate-name fixture (7), the TS fixture (1), terse at 300 symbols (31), and codegraph's own repo at 300 symbols (55). The fork CI test also asserts both paths draw the same file edges, with index weights ≤ CLI weights.

Speed: this repo 48.7s → 1.3s; codegraph's repo, 500 symbols: 2.8s.

Local: node test/run.js 191 passed, 0 failed on the fork and 191/0 on npm 1.6.0. Docs: README, USAGE (speed + troubleshooting), TECHNICAL.md.

Follow-up not in this PR: --diff roots can also be import nodes, which have the same name-probe problem as #46.

…obe per symbol

--architecture spent nearly all its time starting a codegraph process per
symbol (48.7s of this repo's scan; codeshot's own work is ~0.4s). On Node
22.5+ it now reads <path>/.codegraph/codegraph.db once via node:sqlite and
derives each definition's callees from the rows: codegraph's own callee
edge kinds and overload grouping. Enumeration stays on the CLI, so the
symbol set and --max-symbols are unchanged. Anything unexpected (Node
18/20, no index at that path, a schema change, CODESHOT_INDEX_READ=cli)
falls back to the CLI probes.

The read sees every edge, so it drops import-only callees exactly, which
the CLI's one-edge-per-callee JSON cannot. With that rule switched off it
renders byte-identical diagrams to the CLI probes on this repo, two
fixtures, terse and codegraph's own repo. 48.7s -> 1.3s here; 2.8s for
500 symbols of codegraph's repo.
@inth3shadows
inth3shadows merged commit 94e6033 into master Sep 27, 2026
7 checks passed
@inth3shadows
inth3shadows deleted the arch-direct-index-read branch September 27, 2026 11:56
inth3shadows added a commit that referenced this pull request Sep 27, 2026
Follow-up from #46/#47.

`matchRootSymbols` excluded `"kind":"file"` nodes but not
`"kind":"import"` ones. So a changed file's import statements became
bold `--diff` roots, and probing an import's text as a name
(`../src/mcp/tools`) can resolve to another symbol and draw its
callers/callees: the same fabrication #46 fixed for `--architecture`.
Import nodes are now excluded too.

Reproduced on a TS repo with a changed `test/t.ts`: before, two roots
(`runTest` and `"../src/mcp/tools"`); after, only `runTest`. The
regression test was written first and failed on the old code.

Local: `node test/run.js` 192 passed, 0 failed (fork codegraph).
TECHNICAL.md updated.
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