Repository navigation
fix(graph): impact reads a node's edges in one unlimited query again (#3248) - #3249
Open
inth3shadows wants to merge 1 commit into
Open
inth3shadows wants to merge 1 commit into
inth3shadows wants to merge 1 commit into
Conversation
…olbymchenry#3248) colbymchenry#3125 gave impact traversal a node and edge budget, and fetched each visited node's incoming edges as `kind IN (<every kind but contains>) ... LIMIT ?`. Both halves slowed the read the walk makes once per visited node: the kind list searches the target index once per kind, and the LIMIT under the read's ORDER BY made it slower still. getImpactRadius took 2-3x as long for the same subgraph. The walk now reads `WHERE target = ? AND kind != 'contains'` with no LIMIT, through a cached statement, and the slice applies the budget as before. A container's members are read without a LIMIT too, for the same reason. A contains edge still never takes a budget slot or marks the result truncated, and the output is unchanged: the same nodes, edges, order and truncation as main on 20,000 random graphs and 500 traversals of codegraph's own index. Fixes colbymchenry#3248
inth3shadows
added a commit
to inth3shadows/codegraph
that referenced
this pull request
Nov 6, 2026
inth3shadows
added a commit
to inth3shadows/codegraph
that referenced
this pull request
Nov 6, 2026
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.
Fixes #3248
Impact traversal reads each visited node's dependents with one unlimited query again. #3125 turned that read into
kind IN (<every kind but contains>) … LIMIT ?, and both parts slowed down a query the walk runs once per visited node.getImpactRadiustook 2–3x as long for the same subgraph. The node and edge budgets from #3125 still apply, by slicing what the read returns.Changes
src/db/queries.ts: newgetIncomingEdgesExceptContains(targetId), a cached statementSELECT * FROM edges WHERE target = ? AND kind != 'contains' ORDER BY kind, source, line, col. It's one index search ontarget, with the same order asgetIncomingEdges.kind != 'contains'is the predicate the file already uses for this rule elsewhere.src/graph/traversal.ts, ingetImpactRecursive:LIMIT, and the slice applies the edge budget, sotruncatedstill means the budget dropped a dependent;getOutgoingEdges(nodeId, ['contains']), also without aLIMIT;IMPACT_INCOMING_KINDSand theEDGE_KINDSimport are removed, since nothing else uses them.__tests__/graph.test.ts:getIncomingEdgesminuscontains, in the same order;LIMIT(incoming, container, or an extra argument to the new read), andcontainsnever reaches the result, takes a budget slot or marks the result truncated, while a real second dependent over budget does settruncated;tGraph's fake gains the new method.Known limits
These came up in review and are left as they are:
LIMITunder thisORDER BY, which is what made it slow. That includes a walk whose budget is already spent: each further node still costs one full read.EDGE_KINDScount as dependents. An edge whose kind isn't inEDGE_KINDSnow counts as a dependent, as it did before fix(graph): impact stops at a safety budget and says it was truncated #3125, where main's kind list left it out. Nothing in the codebase writes such an edge.limitparameters stay.getIncomingEdgesandgetOutgoingEdgeskeep thelimitparameter fix(graph): impact stops at a safety budget and says it was truncated #3125 added, though impact no longer passes it.getIncomingEdges'ORDER BY. The real-SQLite test fails if the two drift apart.Validation
maxEdges0–11,maxNodes1–8. That gives 0 differences in nodes, edges with their order, andtruncated, across 8,735 truncated runs.AssertionError: expected false to be true, 1 failed;LIMITrestored: it also fails;tsc --noEmitexits 0. Full suite:Test Files 1 failed | 866 passed | 19 skipped (886),Tests 1 failed | 10521 passed. The one failure is the viewer test described at the end (expected 33 to be greater than 300), which fails the same way on main.getImpactRadiusinit/getNode/api/nodeinit/close/getNodeb6ea6179(before #3125)f72c9d2e(main)What each part of the read costs. This is
getImpactRadiusforinit, 5 interleaved rounds on a loaded machine (load average 8–15), so compare the rows with each other:initLIMITLIMITkept,kind != 'contains'LIMITcontainsdropped in JSkind != 'contains', noLIMITImpact on large classes, which also runs the container branch, returned the same subgraph in every build.
CodeGraph(2,417 nodes, 17,449 edges) took 710–900 ms on main and 423–624 ms with this change (load average 15–17). The container change on its own was within noise there, since a walk reads few containers. It's in this PR because it is the same pattern in the same function.The viewer test "the engine's own busiest symbol" still targets
LRUCache.get, whose fan-in is now 33, so it failsfanIn > 300in a checkout that has indexed itself, on main and here alike. Pointing it atCodeGraph.initwould catch this slowdown: it fails on main at 176 and 145 ms. But with the fix it runs at 83–95 ms against a 100 ms limit, too thin a margin to add here. #2646 touches that test; I left a comment there.