Skip to content

perf: reduce computeStress() memory from O(V²) to O(V)#90

Open
sauravbhattacharya001 wants to merge 1 commit intomasterfrom
gardener/perf-stress-memory
Open

perf: reduce computeStress() memory from O(V²) to O(V)#90
sauravbhattacharya001 wants to merge 1 commit intomasterfrom
gardener/perf-stress-memory

Conversation

@sauravbhattacharya001
Copy link
Owner

The previous implementation pre-computed all-pairs BFS shortest paths into a nested Map before iterating over pairs. For a graph with V vertices this allocates V HashMap instances with up to V entries each, plus V² boxed Integer objects — all held in memory simultaneously.

This change computes BFS one source vertex at a time and discards the distance map after processing, keeping only one BFS result alive at any point. The algorithmic complexity is unchanged (still O(V*(V+E))) but peak heap usage drops from O(V²) to O(V+E), which matters for graphs with thousands of nodes where the stress metric is most useful.

Automated gardening by Zalenix 🌱

The previous implementation pre-computed all-pairs BFS shortest paths
into a Map<String, Map<String, Integer>> before iterating over pairs.
For a graph with V vertices this allocates V HashMap instances with up
to V entries each, plus V² boxed Integer objects — all held in memory
simultaneously.

This change computes BFS one source vertex at a time and discards the
distance map after processing, keeping only one BFS result alive at
any point. The algorithmic complexity is unchanged (still O(V*(V+E)))
but peak heap usage drops from O(V²) to O(V+E), which matters for
graphs with thousands of nodes where the stress metric is most useful.
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions bot added visualization Graph visualization and UI size/s labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s visualization Graph visualization and UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant