Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object niche optimization #71

Open
CeleritasCelery opened this issue Apr 19, 2024 · 2 comments
Open

Object niche optimization #71

CeleritasCelery opened this issue Apr 19, 2024 · 2 comments

Comments

@CeleritasCelery
Copy link
Owner

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.

@appetrosyan
Copy link

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.

@CeleritasCelery
Copy link
Owner Author

Objects are implemented as a pointer under the hood.

#[derive(Copy, Clone)]
pub(crate) struct Gc<T> {
ptr: *const u8,
_data: PhantomData<T>,
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants