Open Tr1NgleDev opened 1 month ago
I'm the developer of the hit game 4D Miner (which uses GLM). The vector operator[] calls are getting inlined as switch statements, which aren't getting optimized. There is a lot of code in the game that deals with component indices, so there will probably be a considerable speedup for certain functions if this is merged, and some functions will actually be inlined just because of the changes in this pr.
but this techincally has UB though because the standard allows padding of members of same data type although no implementation does
but this techincally has UB though because the standard allows padding of members of same data type although no implementation does
I would argue that the consistency and performance improvements far outweigh the risks of UB here then. If this can't be merged, then this optimization should probably be removed from type_quat
. I was originally against this for the same reason, but I was unable to find a better solution, and then I learned that the same thing has been done elsewhere in the project for at least 8 years without causing any issues.
If any major compiler ever breaks this, preprocessor checks can be added in the future for that compiler version, or this optimization can be removed altogether. For now at least, considering the large performance gains which have already been demonstrated for a real-world use case, and that this optimization has already been used elsewhere in the project for years, I see no reason this shouldn't be merged.
we already have UB because of union type punning but all compilers define it like C behavior and all compiler defines your issue's behavior and even if not we can add a fallback so this is worth it to implement, I agree with you .
sad that speezing out performance is technically "ub"
to note the thing we lose here is constexpr evaluation for any index but 0. but I would say the performance benefits is worth the change
I would agree. From my experience, the vast majority of use cases for component indexing are when you have to determine which component you are accessing at runtime. Constexpr component indexing seems like a very niche use case that could be done manually with a switch statement if it is ever needed.
the title says it all the explanation for the optimization:
switch/case
(which is also clearly visible if you ever try to RE some code that uses thatoperator[]
)type_quat
so i don't understand why it wasn't done intype_vec
salso
dual_quaternion
operator[]
for some reason didn't use theGLM_ASSERT_LENGTH
macro, so i fixed that.