One of the most painful things in julia is that there is no zero-cost abstraction for bundling gc-visible references with anything. This manifests in allocating views, allocating Tuple{Vector{Int}, Int}
, etc. More than just making some code slow, this severely constrains APIs and design of data layouts.
A priori there is no reason at all that immutable types cannot be always inline (self-referential / circular immutables make no sense and don’t even work in C); TBH, I see no point in immutability for boxed types (or are there any optimizations that become possible due to immutability of a boxed type? And don’t say unboxing, that’s my point!)
So I wanted to ask why this is the case, and whether this pain will go away. There must have been some reason that https://github.com/JuliaLang/julia/pull/18632 was not merged.
And I view this as a breaking change, not an optimization, in the sense that it will completely change best-practice for julia code (julia 0.6: don’t use views, ever; julia 0.7: after profiling and @inline, views might be usable, but YMMV).
Or, still current: Do not write many small inlined functions, write few big ones because you cannot logically bundle arguments and 10-argument functions defy the point. If you have an array that is supposed to hold an immutable with ref-fields, consider splitting your type; each ref-field goes into its own array, and the bitstypes go together into one; except if you do fast random-access reads and are bandwidth not latency constrained, and have many ref-fields, then you should merge them, and eat the additional indirection latency, because otherwise you only use 8 bytes out of every cache-line…argh!)