Juliacon 2024

`Memory` in Julia
07-10, 14:30–15:00 (Europe/Amsterdam), REPL (2, main stage)

Julia 1.11 rewrites Array from being an opaque type implemented mostly in C to being just another type in Julia. In order to do this, we introduced a new, more primitive type for homogenous data storage, called Memory. Then we could re-use that work to add an AtomicMemory type that allow for better expressing multi-threaded memory operations. And along the way, also added the full set of atomic operators to globals, known as Binding types. In this talk, we we will look at the new Memory type, t


Prior to Julia 1.11, Array was a special object in Julia. Operations like resizing and creation had to be done completely in C, which created overhead and made some of the code much harder to write and difficult for the compiler to optimize. Array also had some features that were unnecessary for some uses (e.g. resizing and multiple dimensions) which imposed a small cost. To fix this, in https://github.com/JuliaLang/julia/pull/51319, we added a new, lower level Memory type, which allowed re-implementing all of Array in Julia code on top of it. This moved much of the complexity around resizing and copying an array into pure Julia code. And it allowed a few important data types, that don’t need all of Array’s features (such as Dict), to avoid a small amount of overhead. This has led to some great performance improvements. For example, push! on Array is now roughly ~2x faster, and a number of types in Base now use slightly less memory.
Along the way, we also added support for doing more with atomic operations (especially https://github.com/JuliaLang/julia/pull/52868). By making a simpler Memory type as the basis for an Array, we could also introduce an AtomicMemory that reused most of the same code (and even shares the GenericMemory base class!). This gives both multi-threaded and single-threaded Julia programs alike new and powerful ways of expressing high performance algorithms.