Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

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

Closed
sauravbhattacharya001 wants to merge 1 commit into
masterfrom
gardener/perf-stress-memory
Closed

sauravbhattacharya001 wants to merge 1 commit into
masterfrom
gardener/perf-stress-memory

Conversation

@sauravbhattacharya001

@sauravbhattacharya001 sauravbhattacharya001 commented Mar 19, 2026

Copy link
Copy Markdown
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.

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
Copy Markdown

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
@sauravbhattacharya001

Copy link
Copy Markdown
Owner Author

Closing: superseded or conflicting with newer changes already on main/master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size/s visualization Graph visualization and UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant