Skip to content

Explicit support for AoS/SoA #2634

@HalosGhost

Description

@HalosGhost

Prior Art


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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions