Faster Asin() Was Hiding in Plain Sight
3 days ago
- #mathematics
- #ray-tracing
- #optimization
- The author reflects on the importance of research before acting to save time, using their experience with PSRayTracing as an example.
- A faster approximation for the arcsine function was sought to improve the performance of PSRayTracing, leading to the exploration of Taylor series and Padé approximants.
- Initial attempts with Taylor series showed speed improvements but had significant errors outside the range [-0.8, 0.8], requiring fallback to std::asin().
- Padé approximants were then explored, offering better accuracy with less error, especially when combined with half-angle transformations for edge cases.
- A significant breakthrough came from discovering a fast arcsine approximation from Nvidia's Cg Toolkit, which was both elegant and significantly faster across various hardware.
- Benchmarking showed the Cg approximation was consistently faster than std::asin(), with speedups ranging from 1.02x to 1.89x depending on the hardware.
- The author learned the value of checking existing solutions before diving into complex optimizations, highlighting the importance of community knowledge and historical resources.