Is AOSOA ‘better‘ than SoA?



Is AOSOA really efficient for iteration? For example let us say that we only are interested in the X component which is a float.

Then we would have 4 floats which is 16 bytes, which is only 1/4 of a 64 byte cache line. Also now prefetching would actually also load components into memory that are never accessed.

Of course if we now access X, Y and Z, and Y and Z are also floats, then we would load 48 bytes which is 3/4 of the cache line and we would only waste the H component.

Compared to the "normal SoA" layout [XXXX XXXX XXXX.. YYYY YYYY YYYY.. ZZZZ ZZZZ ZZZ..], where this would be an optimal memory layout if the number of components would be low, otherwise, I assume, we could run into some prefetch issues.

AOSOA seems useful if we iterate almost always over every component in an archetype. And SoA seems better if we have a high number of components per entity but only iterate over a few at a given time.

Did I get something wrong?

Is AOSOA the only supported layout?

 Components are currently laid out in parallel arrays of ComponentData types. We don't move around the components inside your structs currently.

What I was talking about was a research direction to start doing so, and also allowing your code to do so manually.

You're right that there are different trade offs when doing so:

* AOS is better when you're looking at a single, random element and you need all its attributes.
* Pure SOA is great when you're reading only some streams, but is limited by the number of hardware prefetching streams on the hardware (something like 4-8 per core on most commodity hardware)
* AOSOA is great when you have many attributes and you need most of them

In practice we want to allow all these forms, and let users easily transition between them as much as possible.

How are you planning on having that look in practice? Would this be different types (NativeSOA vs. NativeAOS), or would this be a setting on the container (new NativeArray<T>(size, StructLayout.AOSOA))?

Or are we somehow specifying layout in code?

We don't know yet what the final incarnation will be, but at the moment we are experimenting with NativeArraySoA. Basically, we want developers to just change from NativeArray to NativeArraySoA in their job code, and get everything else automatically transformed behind the scenes.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值