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

perf: array-indexed tracking in hittingTimesFrom (eliminates 10k HashSet allocs) - #152

Merged
sauravbhattacharya001 merged 1 commit into
masterfrom
perf/random-walk-hitting-times-array
Apr 3, 2026
Merged

sauravbhattacharya001 merged 1 commit into
masterfrom
perf/random-walk-hitting-times-array

Conversation

@sauravbhattacharya001

Copy link
Copy Markdown
Owner

Summary

Replaces heap-heavy \HashSet\ + \Map<V, Long>\ per-simulation allocations with primitive array-based tracking in \RandomWalkAnalyzer.hittingTimesFrom().

Changes

  • Generation-counter visited tracking: O(1) reset per simulation instead of allocating a new \HashSet(V)\ for each of 10,000 simulations
  • Primitive \long[]/\int[]\ accumulators: eliminates \Long/\Integer\ autoboxing and \Map.get()/\put()\ in the hot inner loop
  • Pre-built \int[][]\ adjacency: cache-friendly neighbor access instead of \Map<V, List>\ lookups

Impact

For V=100: eliminates ~10,000 HashSet allocations (100 elements each), ~200,000 Map operations in the inner loop, and significant GC pressure. The algorithmic complexity is unchanged (same random walks), but constant factors improve substantially.

Testing

Behavioral equivalence: the method signature and return values are identical. The optimization only changes internal data structures from object-based to primitive-array-based.

Replace HashSet<V> + Map<V, Long> per-simulation allocations with
int[]-based tracking in RandomWalkAnalyzer.hittingTimesFrom():

- Vertex-to-index mapping eliminates autoboxing and Map.get() in hot loop
- Generation counter for visited tracking: O(1) reset per simulation
  instead of allocating a new HashSet(V) × 10,000 simulations
- Pre-built int[][] adjacency for cache-friendly neighbor access
- long[]/int[] accumulators instead of LinkedHashMap<V, Long>

For a graph with V=100 vertices, this eliminates ~10,000 HashSet
allocations of 100 elements each, plus ~20,000 Map.get()/put() calls
per simulation in the inner loop.
@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/m labels Apr 3, 2026
@sauravbhattacharya001
sauravbhattacharya001 merged commit 874ac5e into master Apr 3, 2026
3 of 7 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size/m visualization Graph visualization and UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant