-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
Fix #2937: Improve performance of tocolor #3044
Fix #2937: Improve performance of tocolor #3044
Conversation
It should be faster this way 🤔
Did you perform any benchmarks? The |
Unfortunatelly I did not. Didnt have the chance. |
crun t1 = getTickCount() for i=1, 1000000 do tocolor(1, 2, 3, 4) end t2 = getTickCount() outputChatBox(t2-t1) I then added your lua version of tocolor into runcode and it took 444 ms so this proves that this does NOT increase performance and actually degrades performance? As well as the fact that if you have 500 resources, each lua VM has a copy of this tocolor, so it's just unnecessarily increasing memory usage of every resource. |
Hmm, it looks like
This is not a significant increase in memory, if any |
It's nothing about type(). The main reason is function call in lua is extremely slow. That's why i said lua implemented tocolor will decrease performance. And another problem, your code can not work if r g b a are float like 128.5 |
maybe we should focus on fixing "core issue" - you use "tocolor" because "dxDraw" functions need to be called every frame, what if, we design some "widget system" where you declare it, example rectangle, set color once and mta automatically drawing it?
it will be equivalent of onClientRender + dxDrawRectangle every frame |
btw, tocolor is faster enough, dx functions are far more slower |
maybe also need a widget is a number instead of element |
There's actually a really simple fix for this which I already use except in the few cases where the color frequently changes instead of: dxDrawText(blah, tocolor(255, 255, 255, 255), blah) You just add this at top of script: local white = tocolor(255, 255, 255, 255) Then: dxDrawText(blah, white, blah) |
or, just learn to use hex instead of tocolor? tocolor(255, 255, 255, 255) == 0xFFFFFFFF The hex format is |
Best way to increase performance of tocolor (Deprecate tocolor) :merow: |
But things get noticeably worse when you need to change individual components dynamically. Native implementation is better for such cases. |
Im not interested in advancing this PR further anymore. |
Fixes #2937:
Moved
tocolor
into an embedded section. That way it should be faster...?