We recently made some big internal upgrades to improve the performance of raycasts (ie
WorldRoot:Raycast). We’ll be sharing the progress with you here along with some fun technical details.
Also, the max distance of raycasts has been raised from 5,000 → 15,000 studs!
Raycasts are the foundation for large chunks of our technical stack. Roblox uses them internally for Humanoid motion, BillboardGuis, Poppercam, ProximityPrompts, draggers, and other uses that need simple physical queries. Developers use them for collisions, bullets, tracers, suspensions, lasers, and other things that need a high degree of customization.
Time invested in making these faster massively benefits the platform with improvements such as more performant avatars, cameras, etc.
We did a deep dive into the raycast systems and decided to go with a partial rewrite:
- More optimal broadphase → midphase → narrowphase test ordering
- Add ray-OBB test for parts to reduce how many times we fall through to more expensive narrowphase
- New top-down broadphase traversal algorithm
- Used hardware intrinsics (SIMD) to speed up the most common tests, e.g. ray-vs-box
- Started caching part bounding boxes directly on each part
- Improved the memory layout of physics parts for better spatial locality
The performance difference varies based on the workload. You can expect between a 10x improvement on long rays in huge maps with many large parts, to a 0x improvement on a completely empty map.
These changes have been rolling out slowly over the past few months, with one of the bigger changes (the broadphase rewrite) having just released a few days ago. We have a bit of work remaining for accelerating some narrowphase routines, but the majority of the performance improvements should be visible in your maps right now!
We hope you like these improvements. Please share any feedback you have with the team here.
The Simulation Team