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

Turbo-wakers 🚀 #1263

Merged
merged 1 commit into from Mar 30, 2023
Merged

Turbo-wakers 🚀 #1263

merged 1 commit into from Mar 30, 2023

Conversation

Dirbaio
Copy link
Member

@Dirbaio Dirbaio commented Mar 6, 2023

This is a core patch to make wakers 1 word (the task pointer) instead of 2 (task pointer + vtable). It allows having the "waker optimization" we had a while back on WakerRegistration/AtomicWaker, but EVERYWHERE, without patching all crates.

Advantages:

  • Less memory usage.
  • Faster.
  • AtomicWaker can actually use atomics to load/store the waker, No critical section needed.
  • No dyn call, which means cargo-call-stack can now see through wakes.

Disadvantages:

  • You have to patch core...
  • Breaks all executors and other things that create wakers, unless they opt in to using the new from_ptr API.

How to use:

  • Run this shell script to patch core. https://gist.github.com/Dirbaio/c67da7cf318515181539122c9d32b395
  • Enable build-std
  • Enable build-std-features = core/turbowakers
  • Enable feature turbowakers in embassy-executor, embassy-sync.
  • Make sure you have no other crate creating wakers other than embassy-executor. These will panic at runtime.

Note that the patched core is equivalent to the unpached one when the turbowakers feature is not enabled, so it should be fine to leave it there.

This is a `core` patch to make wakers 1 word (the task pointer) instead of 2 (task pointer + vtable). It allows having the "waker optimization" we had a while back on `WakerRegistration/AtomicWaker`, but EVERYWHERE, without patching all crates.

Advantages:
- Less memory usage.
- Faster.
- `AtomicWaker` can actually use atomics to load/store the waker, No critical section needed.
- No `dyn` call, which means `cargo-call-stack` can now see through wakes.

Disadvantages:
- You have to patch `core`...
- Breaks all executors and other things that create wakers, unless they opt in to using the new `from_ptr` API.

How to use:

- Run this shell script to patch `core`. https://gist.github.com/Dirbaio/c67da7cf318515181539122c9d32b395
- Enable `build-std`
- Enable `build-std-features = core/turbowakers`
- Enable feature `turbowakers` in `embassy-executor`, `embassy-sync`.
- Make sure you have no other crate creating wakers other than `embassy-executor`. These will panic at runtime.

Note that the patched `core` is equivalent to the unpached one when the `turbowakers` feature is not enabled, so it should be fine to leave it there.
@Dirbaio Dirbaio changed the title experiment: turbo-wakers. Turbo-wakers 🚀 Mar 30, 2023
@Dirbaio Dirbaio marked this pull request as ready for review March 30, 2023 16:00
@Dirbaio Dirbaio merged commit 5955d81 into master Mar 30, 2023
4 checks passed
@bors bors bot deleted the turbowakers branch March 30, 2023 17:03
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

Successfully merging this pull request may close these issues.

None yet

1 participant