Skip to content

Fix: OptimizedSpatialIndex quadtree slower than DefaultSpatialIndex#19

Merged
YJack0000 merged 2 commits into
mainfrom
fix/optimized-spatial-index-performance
Feb 23, 2026
Merged

Fix: OptimizedSpatialIndex quadtree slower than DefaultSpatialIndex#19
YJack0000 merged 2 commits into
mainfrom
fix/optimized-spatial-index-performance

Conversation

@YJack0000

Copy link
Copy Markdown
Owner

Summary

  • Fix critical quadtree bugs that made OptimizedSpatialIndex slower than DefaultSpatialIndex (linear scan)
  • Implement proper spatial pruning via circle-AABB intersection in _query
  • Fix inBounds rejecting valid queries where center is outside node but range overlaps
  • Optimize update() to skip remove+insert when object stays in same leaf
  • Replace shared_ptr<SpatialObject<T>> with value storage for cache-friendly access
  • Remove leftover debug printf in clear()
  • Re-enable previously disabled test that now passes with the fix
  • Add benchmark test suite for Default vs Optimized comparison

Benchmark Results

Before (buggy)

Scenario Default Optimized Speedup
SimulateFrame 1000 obj, 10 frames 118.68 ms 267.87 ms 0.44x (slower)
Query 5000 obj 156.46 ms 3.10 ms 50.47x
Update 5000 obj 132.67 ms 633.95 ms 0.21x

After (fixed)

Scenario Default Optimized Speedup
SimulateFrame 1000 obj, 10 frames 116.93 ms 15.22 ms 7.68x
Query 5000 obj 156.55 ms 6.23 ms 25.11x
Update 5000 obj 131.25 ms 25.88 ms 5.07x

Test plan

  • All 14 existing unit tests pass (including re-enabled QueryFarAwayButWithinRangeReturnsResults)
  • Benchmark confirms Optimized is now faster than Default in simulation scenarios
  • Verified buggy version is slower via before/after benchmark comparison

🤖 Generated with Claude Code

YJack0000 and others added 2 commits February 24, 2026 03:22
…lower than DefaultSpatialIndex

- Implement circle-AABB intersection (intersectsRange) for spatial pruning in _query
- Replace inBounds check with intersectsRange so queries with center outside node still work
- Optimize update() to skip remove+insert when object stays in same leaf node
- Change spatialObjects from shared_ptr to value storage for cache-friendly access
- Remove leftover debug printf in clear()
- Re-enable QueryFarAwayButWithinRangeReturnsResults test that previously failed
- Add benchmark test suite comparing Default vs Optimized spatial index

Before: Optimized was 0.44x Default (slower). After: 7.68x faster than Default.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The Build step had `if: github.event_name == 'push'` which skipped
compilation on PRs, causing ctest to fail with missing executables.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@YJack0000
YJack0000 merged commit 297ccd2 into main Feb 23, 2026
4 checks passed
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