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

Turn FutureState into an inline type and allocate it using std.ptr.resize #806

Open
yorickpeterse opened this issue Jan 30, 2025 · 0 comments
Labels
performance Changes related to improving performance std Changes related to the standard library

Comments

@yorickpeterse
Copy link
Collaborator

The FutureState type in std.sync is a heap type, meaning that it also includes a header. The way it's used is such that we never make use of that header, resulting in 16 bytes of wasted space per FutureState.

Now that we have support for inline types we can optimize this as follows:

  • We make FutureState an inline type
  • We allocate it using std.ptr.resize
  • Instead of a UInt64 that we cast to an owned value and then forget about, we use a Pointer[FutureState] and access the fields through that pointer

This will probably require some manual fiddling with pointer offsets for e.g. access to the atomic state

The tricky thing/downside is that we'd depend on FutureState having a specific layout. While this is currently true, it's not something that we guarantee. We can't use an extern type as these can't be generic.

@yorickpeterse yorickpeterse added performance Changes related to improving performance std Changes related to the standard library labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Changes related to improving performance std Changes related to the standard library
Projects
None yet
Development

No branches or pull requests

1 participant