ArticleslgStudy

computer science

AoS and SoA

AoS and SoA is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand AoS and SoA rather than just read about it. In short: In computing, an array of structures (AoS), structure of arrays (SoA) or array of structures of arrays (AoSoA) are contrasting ways to arrange a sequence of records in memory, with regard to interleaving. This is of interest with respect to software performance, especially when utilizing data-parallel operations, such as SIMD or SIMT.

Key takeaways

  • AoS and SoA belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect AoS and SoA to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of AoS and SoA from memory before moving on to harder problems.

Reference excerpt

In computing, an array of structures (AoS), structure of arrays (SoA) or array of structures of arrays (AoSoA) are contrasting ways to arrange a sequence of records in memory, with regard to interleaving. This is of interest with respect to software performance, especially when utilizing data-parallel operations, such as SIMD or SIMT.

Structure of arrays

Structure of arrays (SoA) is a layout separating elements of a record (or 'struct' in the C programming language) into one parallel array per field. The motivation is easier manipulation with packed SIMD instructions in most instruction set architectures, since a single SIMD register can load homogeneous data, possibly transferred by a wide internal datapath (e.g. 128-bit). If only a specific part of the record is needed, only those parts need to be iterated over, allowing more data to fit onto a single cache line. The downside is requiring more cache ways when traversing data, and inefficient indexed addressing. For example, to store N points in 3D space using a structure of arrays:

Array of structures Array of structures (AoS) is the opposite (and more conventional) layout, in which data for different fields is interleaved. This is often more intuitive, and supported directly by most programming languages. For example, to store N points in 3D space using an array of structures:

Array of structures of arrays Array of structures of arrays (AoSoA) or tiled array of structs is a hybrid approach between the previous layouts, in which data for different fields is interleaved using tiles or blocks with size equal to the SIMD vector size. This is often less intuitive, but can achieve the memory throughput of the SoA approach, while being more friendly to the cache locality and load port architectures of modern processors. In particular, memory requests in modern processors have to be fulfilled in fixed width (e.g., size of a cacheline. The tiled storage of AoSoA aligns the memory access pattern to the requests' fixed width, leading to fewer access operations to complete a memory request and thus increasing the efficiency. For example, to store N points in 3D space using an array of structures of arrays with a SIMD register width of 8 floats (or 8×32 = 256 bits):

A different width may be needed depending on the actual SIMD register width. The interior arrays may be replaced with SIMD types such as float32x8 for languages with such support.

Alternatives Between the pure AoS and SoA extremes lie several hybrid layouts. AoSoA (array of structures of arrays), also called tiled or strided/"striped" SoA, interleaves records in blocks whose size is a multiple of the SIMD lane width: this keeps contiguous vector loads for each field while preserving locality when several fields of the same record are accessed together. Intel's optimization guidance recommended such a hybrid layout as early as the 1999 IA-32 optimization manual, and it collapses to AoS when the block size is one and to SoA when the outer array size is one.

4D vectors AoS vs. SoA presents a choice when considering 3D or 4D vector data on machines with four-lane SIMD hardware. SIMD ISAs are usually designed for homogeneous data, however some provide a dot product instruction and additional permutes, making the AoS case easier to handle. Although most GPU hardware has moved away from 4D instructions to scalar SIMT pipelines, modern compute kernels using SoA instead of AoS can still give better performance due to memory coalescing.

Software support

Most languages support the AoS format more naturally by combining records and various array abstract data types. SoA is mostly found in languages, libraries, or metaprogramming tools used to support a data-oriented design. Examples include:

"Data frames", as implemented in R, Python's Pandas package, and Julia's DataFrames.jl package, are interfaces to access SoA like AoS. The Julia package StructArrays.jl allows for accessing SoA as AoS to combine the performance of SoA with the intuitiveness of AoS. Code generators for the C language, including Datadraw and the X Macro technique. Automated creation of AoSoA is more complex. An example of AoSoA in metaprogramming is found in LANL's Cabana library written in C++; it assumes a vector width of 16 lanes by default.

References

Worked examples

Example 1 — a first encounter with AoS and SoA

Start with the simplest possible case. Write down what AoS and SoA claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to AoS and SoA before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about AoS and SoA ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of AoS and SoA

In research
AoS and SoA appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses AoS and SoA in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
AoS and SoA is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data-oriented programming, Data orientation, SIMD computing, so understanding it makes those chapters shorter.
In everyday life
Look for AoS and SoA outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “AoS and SoA” →

How to study AoS and SoA in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what AoS and SoA means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain AoS and SoA out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is AoS and SoA in simple terms?

In computing, an array of structures (AoS), structure of arrays (SoA) or array of structures of arrays (AoSoA) are contrasting ways to arrange a sequence of records in memory, with regard to interleaving. This is of interest with respect to software performance, especially when utilizing data-paral…

Why does AoS and SoA matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study AoS and SoA?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on AoS and SoA.

Tags

  • Data-oriented programming
  • Data orientation
  • SIMD computing

Keep exploring