>small union which julia handles efficiently at runtime
Oh! I didn't realize Julia already optimized small unions.
https://julialang.org/blog/2018/08/union-splitting/ https://docs.julialang.org/en/v1/devdocs/isbitsunionarrays/
I wasn't quite sure whether something like this was possible given the semantics of Julia.
Personally, I'd still prefer something more explicit, so it would be more obvious when a union is being handled efficiently. But given that small unions are optimized, I can see why Julia would make the opposite decision.
This makes me feel a lot better about writing Julia code with union types. Thanks
Re:From Julia to Rust
by eigenspace on Tuesday June 08, 2021 @12:50PM
(#27437639)
Yep, small union optimizations are a godsend!
No, of you look at the typed IR I posted, it says
and So it's inferred properly to be a small union which julia handles efficiently at runtime: > Furthermore, TypeStable itself has to be on the heap, which I think means this causes two pointer lookups rather than just one.It's on the heap because you wrote
in your example and I was just mimicking you as close as possible. If you don't actually want it to be mutable, then you can just remove the keyword mutable and it'll be even faster and have no heap allocations: