-
-
Notifications
You must be signed in to change notification settings - Fork 410
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
Improve performance of tocolor #2937
Comments
Hi, function tocolor(r,g,b,a)
return math.floor(b) + math.floor(g) * 256 + math.floor(r) * 256 * 256 + math.floor(a or 255) * 256 * 256 * 256;
end |
It's a bad practice to invoke tocolor every frame [assuming that a color is immutable]. The result of this function should be cached somewhere. Or even better to use a hexadecimal number like 0xFF00FFFF. |
Sorry, your "floor" ruins the whole optimization. Without floor its twice as fast as tocolor, but with floor its twice as slow. I highly suggest just checking for yourself that you dont put wrong arguments into this wrapper function instead of doing this check for every tocolor() call. |
It won't optimise speed, instead, it will decrease performance |
Is your feature request related to a problem? Please describe.
This function is very, very often used, on almost all servers in render loops,
mtasa-blue/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp
Line 714 in 228f881
Describe the solution you'd like
move implementation to lua to decrease context switch, example implementation:
Describe alternatives you've considered
/
Additional context
:cat
Security Policy
The text was updated successfully, but these errors were encountered: