#regarding the performance of accessing

1 messages · Page 1 of 1 (latest)

torpid marlin
#

future me: yeah you lazy sob, add .ToArray and gain 3x speed

wispy hawk
#

Well, managed arrays have their own dedicated IL instructions for reading and writing to them, so JIT can easily optimize it.

But I think if you convert the NativeArray to a Span, you should see major improvements.

#

This can be done without any additional allocations, since Span can reference native memory.

#

Unity 2022.2+ have NativeArray.AsSpan, but you can also do it manually using GetUnsafePtr and passing that into the Span constructor. It just requires an unsafe context.

wispy hawk
#

I just tried this and got about a 50% speed improvement. Which is only a little bit faster than ToArray, except no allocation.

arctic ingot
#

and you're not profiling in the editor with safety checks on, right? Because that adds a ton of overhead that won't be present in actual use cases

torpid marlin
maiden locust
torpid marlin
wispy hawk
torpid marlin
#

and same perf as ToArray but without the silly allocation

maiden locust
#

still concerned about the time it takes

torpid marlin
maiden locust
torpid marlin
#

the Draw.WireBox command is like Drawgizmo but 100x faster

maiden locust
torpid marlin
maiden locust
torpid marlin
#

and feed the voxel navigation system as well so that flying creatures dodge or dive in the liquid

#

compute butter.GetData spits out a flat array

maiden locust
#

another note would be to use unity mathematics instead of default unity Mathf functions, mathematics should be faster than Mathf and also are designed to work onto jobs. I am not sure if it would be necessary to convert vector3 to float3, not sure if it actually improves performance, but In my voxel project I did that just in case

torpid marlin
#

in the past mathematics had an overhead so in main thread there was a penalty, but if I jobify this I'll switch over. someone told me that vector3 is already float3 under the hood

maiden locust
torpid marlin
maiden locust
#

your ms should go lower

torpid marlin
#

on 11 threads instead of 1

#

yes it should be around 0.1 ms or even lower