Skip to content

Conversation

@ayush4874
Copy link
Contributor

I noticed the main simulation loop in Network.run had some overhead from repeated checks that don't change during a run (like single_clock and device).

I refactored it to split the "fast path" (single clock) from the multi-clock logic.
Also, timestep[0] is a numpy scalar, which is surprisingly slow to access in a hot loop. I replaced it with a local integer counter just for the loop condition.

Benchmarks (1M steps, pure Python):

  • Before: ~7.99s
  • After: ~7.59s
  • Speedup: ~5%

Verified that stop() and NetworkOperation still trigger correctly with the new logic.

Split the run loop to avoid invariant checks for single-clock sims. Also swapped slow numpy scalar lookups for local int tracking. Benchmarks show ~5% speedup while keeping stop() working.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant