Swift 6.2 introduces InlineArray, a new low-level data structure designed to improve performance and memory efficiency in specific scenarios. While most developers will continue using Array in everyday code, InlineArray fills an important gap for performance-critical paths where allocation cost, cache locality, and predictable memory layout matter.
In this article, we’ll explore what InlineArray is, why Apple added it, how it works internally, and when you should (and should not) use it. We’ll also walk through practical examples to understand its behavior and limitations.
Swift’s standard Array is powerful and flexible, but that flexibility comes with overhead:
In performance-sensitive systems—such as SwiftUI internals, compiler tooling, numeric code, or tight loops—this overhead can become measurable.
Apple introduced InlineArray to solve a very specific problem:
Store a small, fixed number of elements directly inline, without heap allocation.
This design enables:
InlineArray is a fixed-size, value-type collection whose elements are stored inline within the value itself, rather than in heap-allocated storage.
Conceptually:
Array<T> - dynamically sized, heap-allocatedInlineArray<T, N> - fixed size N, stack-like inline storageAn InlineArray is defined with:
let numbers: InlineArray<Int, 4> = [1, 2, 3, 4]Element access is similar to Array:
let values: InlineArray<Int, 3> = [10, 20, 30]
print(values[0]) // 10
print(values[1]) // 20Indexing is bounds-checked, just like Array, ensuring safety.
InlineArray is a value type, so mutation works as expected:
var scores: InlineArray<Int, 3> = [80, 90, 100]
scores[1] = 95However, you cannot append or remove elements:
// ❌ Not allowed
scores.append(110)The size is fixed at compile time.
Let’s compare the two side by side:
| Feature | Array | InlineArray |
|---|---|---|
| Size | Dynamic | Fixed |
| Storage | Heap | Inline |
| Allocation | Yes | No |
| Resizable | Yes | No |
| Performance | General-purpose | Optimized for small sizes |
| API richness | Very high | Intentionally minimal |
The biggest advantage of InlineArray is memory layout predictability.
Because elements are stored inline:
This is especially beneficial in:
Instead of:
struct Vector3 {
var values: [Float]
}You can now write:
struct Vector3 {
var values: InlineArray<Float, 3>
}
let position = Vector3(values: [1.0, 2.0, 3.0])Benefits:
You can iterate using standard loops:
let colors: InlineArray<String, 3> = ["Red", "Green", "Blue"]
for color in colors {
print(color)
}This feels familiar while preserving the fixed-size guarantees.
You can convert an InlineArray to a standard Array when needed:
let inline: InlineArray<Int, 4> = [1, 2, 3, 4]
let array = Array(inline)This is useful when interacting with APIs that expect [T].
InlineArray is not a replacement for Array. It shines in narrow, well-defined cases.
Array functions like append(), filter(), or map()Apple intentionally kept InlineArray minimal:
This makes misuse harder and intent clearer—an important principle in Swift’s evolution.
InlineArray is a powerful addition to Swift, but it’s a specialized tool, not a general-purpose collection. For most application-level code, Array remains the best choice. However, when you need precise control over memory layout and performance, InlineArray provides a safe, expressive alternative without sacrificing Swift’s core principles.
If you’re building frameworks, performance-sensitive components, or low-level abstractions, InlineArray is well worth understanding and adopting thoughtfully.
Thank you for reading. If you have any questions feel free to follow me on X and send me a DM. If you enjoyed this article and would like to support me, Buy me a coffee.