Skip to content

iterative Tarjan SCC to avoid stack overflow on large graphs#49

Open
LdDl wants to merge 7 commits into
masterfrom
refactor/tarjanScc
Open

iterative Tarjan SCC to avoid stack overflow on large graphs#49
LdDl wants to merge 7 commits into
masterfrom
refactor/tarjanScc

Conversation

@LdDl
Copy link
Copy Markdown
Owner

@LdDl LdDl commented Apr 15, 2026

recursive Tarjan risks uncontrolled Go stack growth on city-scale graphs with deep DFS chains (100k+ vertices). Iterative version bounds memory explicitly so I've replaced recursive strongConnect with iterative version using explicit call stack:

  • Pre-build flat adjacency list (CSR-style) - single allocation instead of per-vertex map iteration
  • Reuse call stack buffer across strongConnect invocations
Metric Before After Delta
ns/op 36,351,165 36,121,026 -0.6%
B/op 15,507,960 19,277,907 +24%
allocs/op 8,058 8,198 +1.7%

graph has 40k vertices: time and allocs are changed barely. Also +3.8MB is the one-time cost of the flat adjacency buffer - negligible compared to the graph itself.

@LdDl LdDl self-assigned this Apr 15, 2026
@LdDl LdDl added experimental enhancement New feature or request core labels Apr 15, 2026
@LdDl LdDl added the wontfix This will not be worked on label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core enhancement New feature or request experimental wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant