-
Notifications
You must be signed in to change notification settings - Fork 332
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
Switch vector and angle types to use userdata types #2399
Conversation
Constantly calling the vector and angle constructors is pretty bad for performance (especially needlessly as angle and vector were doing). This converts the e2 vector and angle types to only support gmod userdata (rather than also supporting tables with three numbers)
Besides the extension compact which will never be fixable, this also breaks anything that relies on using doubles as both vector and angle use floats for their numbers. |
Should be all of them. Scanned over e2function vector|angle
**DO NOT MERGE THIS UNTIL wiremod/wire#2399 IS MERGED.** This PR converts functions that return a table with three numbers to proper Vector/Angle userdata, since that is what vector and angle types will now use in E2 for efficiency. I'm sweeping through found instances of this on github and making these PRs to make sure the amount of extensions broken by this is minimal.
**DO NOT MERGE THIS UNTIL wiremod/wire#2399 IS MERGED.** This PR converts functions that return a table with three numbers to proper Vector/Angle userdata, since that is what vector and angle types will now use in E2 for efficiency. I'm sweeping through found instances of this on github and making these PRs to make sure the amount of extensions broken by this is minimal.
Should be faster than unpack
Will merge tomorrow if there's no issues @dvdvideo1234 @Linus045 @HyvelEurope |
**DO NOT MERGE THIS UNTIL wiremod/wire#2399 IS MERGED.** This PR converts functions that return a table with three numbers to proper Vector/Angle userdata, since that is what vector and angle types will now use in E2 for efficiency. I'm sweeping through found instances of this on github and making these PRs to make sure the amount of extensions broken by this is minimal.
Did this actually help performance? Starfall found this way of doing things to be much slower. |
wdym? starfall can't do this, since you provide stuff like I haven't benchmarked, but if it is slower, it's likely that some functions (especially from external extensions) aren't ported over yet and still support the old types, plus I haven't refactored out wire/lua/entities/gmod_wire_expression2/core/e2lib.lua Lines 52 to 58 in cc90f68
Hopefully it can be changed to use a compile time lookup with types |
No, it's slower because creating Vector and Angle objects and using their metamethods is much slower than doing it in native lua. Starfall used to use the glua objects until we ported all the math to lua. |
Either way this is more oriented toward being able to use vector and angle properly as their glua types in physics E2s. Creating a userdata and using that throughout the whole variable's lifetime is much better than constant calls to create Vector/Angle for each function call onto it. It's the same as removing Color() call pollution in draw hooks, to me. If you just want a simple data structure without calling into glua types, you could use vector2/vector4/array/table, but 90% of the time you should be using vector/angle for physics / using in glua function calls. Although, E2 not having a |
Another big shame is that glua and e2's vector apis are opposite, glua has mostly self-modifying operations, e2 has only copying-operations, so there are copies made in a good amount of cases anyway. |
For now I think I'll keep two separate branches. One with the V/A mod and one without. I see the workshop is running this revision https://steamcommunity.com/linkfilter/?url=https://github.com/wiremod/wire/commit/7ed23af5b8fd800cb7e520bf7cfba4b813bfc1ae and the git HEAD is way ahead of it. Then in a way WORKSHOP users can install my master branch ( as it is right now ) and GIT users can install branch wire-pull-2399 |
The E2
vector
andangle
types supported both theVector
andAngle
gmod userdata types, as well as tables with three numbers in them. Since it had no idea which it was dealing with, it instead treated all of them as tables with three numbers, requiring constant calls to the vector/angle constructors for use in actual glua functions. This converts the e2 vector and angle types to only support gmod userdata (rather than also supporting tables with three numbers).This should boost performance a good bit especially for physics/angle heavy E2s (and I still will need to make another PR to replace fixDefault to use a function, for further perf boosts)
Because of this, maybe we want to reach out to common extension creators to update their extensions to use the userdata instead. (Although I checked @sirpapate's extensions, they don't seem to return vector or angle, so should be fine.)
Fixes #2218