-
Notifications
You must be signed in to change notification settings - Fork 394
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
Add 2-component vector constructor #1569
Add 2-component vector constructor #1569
Conversation
Thanks for the comments. Pushed a revision that addresses all the points mentioned. Also added a new micro benchmark for vector library. Test results: LuauVector2Constructor false:
LuauVector2Constructor true:
Command line used: Tested on: Windows 10, MSVC 2022, Intel i5-3570K The difference is a bit less than 1% in favor of the old version. I don't think this will make a big difference in practice though. I also ran the test with only two arguments (the new LuauVector2Constructor path):
Creating vectors from two components is now much faster as expected (previously ~218ms on average with a user defined 2D constructor without the fastcall). An idea for future work: we could consider adding a new built-in for the 2D case (luauF_vector2). This would get rid of the extra branch in luauF_vector and get back that 1% and make luauF_vector2 even faster. This would require detecting the number of arguments in the compiler and choosing the correct builtin. Not sure if it makes sense to add complexity for such a small gain though. |
Sorry for the delay. |
I actually kind of expected to see that :D Code looks good, but need a code merge. Hopefully the definitions conflicts will not cause too much pain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to re-request after merging.
Thanks! I'll fix the conflicts next.
I was actually thinking that the 3/4-comp fastcall would not need to handle 2 arguments and fallback to the slow path instead. It should be rare that the compiler cannot deduce number of arguments in practical use cases. But anyway, I agree that it would be a premature optimization at this point. |
Conflicts have now been fixed, could you recheck please? EmbeddedBuiltinDefinitions.cpp is quite messy indeed when there are multiple feature flags. 2 flags per library is sort of doable but with more it's going to be hit by combinatorial explosion. Maybe there's a better way... |
Thank you. |
Implement RFC: 2-component vector constructor. This includes 2-component overload for
vector.create
and associated fastcall function, and its type definition. These features are controlled by a new feature flagLuauVector2Constructor
. Additionally constant folding now supports two components whenLuauVector2Constants
feature flag is set.Note: this work does not include changes to CodeGen. Thus calls to
vector.create
with only two arguments are not natively compiled currently. This is left for future work.