What will be faster: CFrame manipulations, or Vector3 ones?

Hello guys. As you know (most likely), CFrames have 4 vectors, which represent position and rotation. But, if CFrames consist of vectors, I got question: can I remade CFrame’s functions to work with Vector3, then using CFrame.fromMatrix() and increase performance with such thing, or it will be a bad idea?

Note: I care more about performance, speed of code, not about it’s readability and lengths (although if I can I care about both)

1 Like

From luau-lang.org:

…which essentially means we have native 3-wide SIMD support. For code that uses many vector values this results in significantly smaller GC pressure and significantly faster execution…

In other words, doing math on Vector3s is going to be optimized quite a bit. So, my guess is that doing the math on the vectors themselves is probably going to be faster. However, always benchmark it yourself to verify.

CFrames should have 2 vectors, a “Position” and “Rotation”, that would optimize it.

It seems very unlikely there is a gain to be found. Cframes are all over the Roblox api, so it seems likely they will be implemented in an efficient way already.

If you have some code that is computationally intensive, you would be better off looking at opter optimisations. Or maybe play with this beta:

The reason CFrame’s require 4 vectors is because 1 is assigned for the position but the other 3 are required for the actual rotational matrix in 3d space.

1 Like

Yeah, but I think 1 vector is more optimized than 3 normalized vectors*

LEAST what we can use to make rotation is 2 vectors, and to get third, you will need to cross it. You can’t represent rotation with only 1 vector. Only XYZ-like rotation (Like FromEulerAnglesXYZ). But this leads to precision problems.

if that’s true then just add a CFrame type with Position and Rotation vector (two vector) that will be a “low precition CFrame”.

Why someone will need that new type when CFrame is already good?

for optimization purpose only

character limit

If it’s really that serious then you can also try quaternions

1 Like