Does Unity Physics 2D utilize BVH?

Hi, I’m pretty new to Unity so bear with me.

After running some tests where I try out Unity Physics 2D functions such as raycast2D and OverLapBoxAll2D, I notice that the performance for these 2 functions seem to improve when increasing the distance between the numerous gameObjects that call these increases, leading me to believe that they utilize some kind of Barnes-Hut approximation method, or Bound Volume Hierarchy in other words. I have trouble deciphering the documentation regarding the nature and implementation of these functions. I’ve also read on unity forums about implementing your own custom BVH to handle physics, but fail to see how that is relevant if Unity already has one.

I’ve also noticed that Unity has a BoundingVolumeHierarchy struct in the Physics namespace (Struct BoundingVolumeHierarchy | Package Manager UI website) , but I’m having trouble deciphering its correlation to raycast and overlapbox functions, and if it is even applicable to the 2D physics. If someone could point me in the direction of where this is mentioned, some source code unity perhaps uses that relates to this, I would be grateful. Does unity even use bounding volume hierarchy for raycasting and overlapbox in 2D? Is there some other alternative method that Unity uses to speed up these functions?

It’s Box2D. The code for that and its broadphase is on Github: b2DynamicTree

Broadphase raycast.

As a side-note: If you’re talking about performance, don’t use the “All” queries; those create an array and it always ends up being thrown at the GC.