Yea I did actually read through that thread after posting. I see it concludes with inSight01 achieving a 0.0146ms for a single batched raycast for a scene with a single cube in it…
I’m getting ~10x that cost for a single raycast in a more complex scene that includes a terrain and ~hundred or so other colliders. So maybe this is not unreasonable and I just have unrealistic expectations. I saw your comment on job overhead but I’ve also tried this using Run() on the main thread and it didn’t change much.
I’m still confused why the sphere cast is faster. I’ll try some more tests and report back.
Since I know more information about what I want from the raycasts in question I ended up replacing them with a hybrid voxel cast with a simple ray to heightmap cell plane intersection when near the heightmap. This gave a ~37.5* speed-up over using a standard raycast on the heightmap.
Not a critique of Physics as such as I guess it has to solve for the general case, like lots of things in Unity. Maybe Unity physics is simply doing a ray to non-convex mesh intersection test for this situation currently.
What is the performance of raycasts if you enable RayTraceCamera in any of the physics samples (Physcs Scene Basic Element > Main Camera > RayTraceCamera)
If raycast performance there is as expected, you can actually copy the necessary scripts and RayTraceUI component from samples into your game and test it there as well.
I haven’t used Unity much, but fyi, sphere casts are really cheap. just a distance check. I would not be surprised if it’s cheaper than a raycast. Though, how the underlying spatial partition is setup is a huge variable that can impact performance one way or the other.