-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 Vec3 Support for setFromEulerAngles() pc.Quat function #4139
Conversation
No need to clone (it will lead to memory allocations, which then lead to minor/major GC stalls). if (ex instanceof Vec3) {
const vec = ex;
ex = vec.x;
ey = vec.y;
ez = vec.z;
} Also, it makes |
Good idea @Maksims . Compound values are assigned by reference in JavaScript so it would not create a new copy of the object. Plus it's safer because the order in which ex, ey, and ez are assigned doesn't matter in your idea. |
Thanks to @kungfooman for the suggestion to simplify use. Thanks to @Maksims for pointing out no need to clone when input is Vec3, just a reference is enough.
@kungfooman Good idea. I pushed another commit in this PR based on your suggestion. |
Why still check if its a Not sure if I'm missing something, I didn't test it. Good job! |
@kungfooman Another good point. The instanceof check in the 4 lines you mentioned are redundant. I removed them and the tests still pass. |
No longer need to check if x instanceof Vec3 when x is passed as input to setFromEulerAngles() pc.Quat function.
This is great - thanks!! 🙏 |
Fixes #3663
Discussion
I thought of two ways to instantiate
ex
,ey
, andez
given the condition whereex instanceof Vec3
is true:ex = ex.x
last so we don't have to make a clone ofex
. A rule of thumb in software development is that "premature optimization is the root of all evil". However, I think it is okay to bend the rules in this situation since this is a game engine where performance matters. If a reviewer says otherwise, I will make changes based on their suggestions.ex
and use the clonedVec3
to instantiateex
,ey
, andez
. Depending on the person, this option might be easier to understand than option 1. But there is a small performance penalty because this creates an extraVec3
object.I confirm I have read the contributing guidelines and signed the Contributor License Agreement.