-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[rmodels] DrawSphereEx()
optimization
#4106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Precalculates sin/cos to eliminate unnecessary calls.
OBO error -- added 1 additional precalculated cos/sin value to each array to complete the 360-degree wraparound. Technically the value of these last elements will always be the same as the first element due to 360-degree wraparound, but this is the simplest solution.
I have another version without calloc/free, but it's not faster (than the calloc version) on my machine. If someone wants to play around with it:
|
@smalltimewizard I'd prefer to avoid allocators inside the function, what is the improvement wihtout the allocators in comparison to original version? |
I get 65 ms frametime from my benchmark with no allocators (for a sphere with 16 rings and 16 slices, the no allocators algorithm makes 612 cos/sin calls). |
@smalltimewizard I'm reviewing those numbers and they seem irregularly big, are we talking about In any case, I'm considering if this change really worth it because I adds an extra level of code complexity for newcomers and readibility for future maintenance, for the performance benefit it provides. EDIT: I see those numbers are computed for 1000 spheres, what is exactly computed? A for loop calling this function 1000 times? I think it should be measured just the function body 1 time for more accurate numbers (or 1 function call). |
DrawSphereEx()
optimization
New barebones benchmark:
On my machine (mingw-w64, compiled as Release, static library) for 1000 DrawSphereEx() calls: |
@raysan5 Rebuilt DrawSphereEx from scratch -- the new one uses stack allocation and is hopefully simple enough. |
@smalltimewizard Thanks for the improvement! I'm merging it but I will also keep the original one for educational pouposes |
Removed unnecessary cos/sin usage in DrawSphereEx(). For a sphere with 16 rings and 16 slices (as with DrawSphere()), 8640 cos/sin calls pre-optimization are reduced to 72.
Benchmark (1000 spheres):
I compiled raylib (mingw-w64, static, Release) without and with the optimization. On my machine, the above benchmark gives a 75 ms frametime without, 50 ms with the optimization.