Repository navigation
perf: optimize open list heap, neighbor traversal and loop checks - #94
millisdoe-glitch wants to merge 1 commit into
Conversation
|
This introduces a new list. Have you verified the memory impact on that? |
|
Thanks for reviewing! To clarify: no new list is allocated:
Memory Verification (
|
| Branch | Peak Memory (tracemalloc) |
Heap entry tuple size |
|---|---|---|
main (before) |
10,761.01 KB | 80 bytes (f, count, x, y) |
| This PR (after) | 10,754.75 KB | 72 bytes (f, count, node) |
| Delta | -6.26 KB (-0.06%) | -8 bytes per entry |
Memory usage actually decreases slightly because storing (node.f, count, node) uses a 3-element tuple instead of a 4-element coordinate tuple, referencing the already-allocated GridNode object directly with zero additional allocations.
Summary of changes
This PR introduces several focused performance optimizations to the core pathfinding loop, heap management, and grid neighbor traversal without changing any public APIs or algorithms:
Direct node storage in SimpleHeap:
ode.
Streamlined Grid.neighbors() traversal:
Explicit GridNode.eq:
Throttled loop checks in Finder.keep_running():
Direct attribute access:
Benchmark & Performance Impact
Tested on a 500x500 grid with obstacles (adapted from est/test_performance.py):
Total function calls during a 500x500 A* search reduced from 6,190,821 to 3,774,815 (over 2.4 million fewer function calls).
Compatibility & Tests