-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Prior Art
- builtin function @reify to create a type from a TypeInfo instance #383
- Data Oriented Design? #2078
- Add .stride field to slices #2255
- https://en.wikipedia.org/wiki/AOS_and_SOA
This issue is meant to serve as an issue to address the specific question of how Zig can, should, and (eventually) will provide support for smoothly transitioning between SoA and AoS.
The AoS strategy (an array of structures) is often more natural, and allows simpler code. However, the SoA strategy (where there is only a single structure, embedding arrays) is often more performance friendly for cache layout and SIMD optimization. Unfortunately, in most languages (as in Zig for the moment), switching between these strategies requires large refactoring.
The experimental (and still only privately-available) programming language named jai provides for novel tooling to dramatically simplify this transition. Jai offers a special tag that can be placed on structure definitions (SOA
). When a struct is tagged with SOA
, the code is still written as it would be for the AoS strategy, but the memory layout will transparently be SoA. This allows for several pros:
- developers can write code in the most intuitive fashion regardless of which memory layout is more performant for the situation
- this language support offers the refactor as a single-line change rather than refactoring all the related code
The obvious con is that this bit of tooling is very specific (rather than being something more generalized for memory layout). Additionally, it is an extra bit of special syntax rather than something implemented in the language itself.
@tgschultz put together a short prototype of implementing this behavior within Zig which relies on this helper struct.
This issue can be considered an open question and request for proposal for solution.