rune
rune copied to clipboard
Object niche optimization
Currently the core object type is represented as a raw point *const u8
. A value of nil
is represented by a null pointer. If we changed this to a NonNull<u8>
, it would enable types like Option<Object>
to be only a single word. However we would have to change the value of nil
to something else (most likely 1). Not sure if this would be worth it, because we use nil
a lot more than we do Option<Object>
, but if changing nil to 1 instead of 0 had no real effect then it could be worth while.
This is a low-level optimisation that can be carried out at any point, the main issue is that the less raw pointers are exposed the better. In Rust even things like vec
never get allocated with a null value… so I strongly recommend avoiding raw pointers at all costs.
Objects are implemented as a pointer under the hood.
https://github.com/CeleritasCelery/rune/blob/45dc497f77a1664c7b6a89991b3070723bd4cc2f/src/core/object/tagged.rs#L57-L61
There is not really a way to avoid that since they can encode integers and are also tagged. But we could change from a raw pointer to a NonNull<T>
if we wanted to allow niche optimizations. As you said though, that could be carried out at any point without impacting the rest of the code.