OK, AABB trees + pairs wasn't particularly fast. Time to try grid-based approach