Vector & Color :GetComponents()

As a Roblox developer, it is currently too hard to performantly access the components of vectors and colors.

If Roblox is able to address this issue, it would improve my development experience because it would drastically improve the performance when using the components of these data types.

On my hardware CFrame:GetComponents() runs roughly 2x-3x as fast as vector3.X, vector3.Y, vector3.Z. It’s comparable to simply vector3.X. This is a super large difference, and, it has been a performance road block in some of my code that’s resulted in me having to use my own data types for vectors in some areas.

The cost of this indexing is almost nothing, its less than 0.01 milliseconds or 0.03 for all three, but, this really adds up when doing millions of operations, or, even just hundreds of thousands. My voxel generator suffers pretty greatly from having to index the X Y and Z components of cell positions, it equates to about 0.1 seconds of the generation time which is about an 8th on average. Based on my benchmarks a similarly performant :GetComponents() for Vector3s would reduce that down to ~0.03 seconds which is almost nothing compared to the total time of generation, it’d pretty much eliminate the cost from being a worry for me.

Similarly, Color3s, Vector2s, and CFrames seem to have similar performance issues purely because of the addition index.

:GetComponents() would be great for a lot of data types because of its speed, and, it’d make swapping between different data types a lot easier. It’d allow for these sorts of things:

local color = Vector3.new(color3:GetComponents())
-- Do some math on color
color3 = Color3.new(color:GetComponents())

Not only would that be a lot faster, it’d be a lot easier to use since you’re not needing to write out color.X, color.Y, color.Z, color3.r, color3.g, and color3.b.

25 Likes