Skip to content

improve performance by reusing the waker#30

Merged
zesterer merged 1 commit into
zesterer:masterfrom
fereidani:master
Nov 19, 2025
Merged

improve performance by reusing the waker#30
zesterer merged 1 commit into
zesterer:masterfrom
fereidani:master

Conversation

@fereidani

Copy link
Copy Markdown
Contributor

Hi,
This PR improves performance by avoiding Waker creation from the Signal on each call.
It greatly improves performance according to my benchmarks.
Hopefully it will get merged in the next two years (joking 😂).

@zesterer

Copy link
Copy Markdown
Owner

Nice catch. I can see how this should be faster in theory.

In practice, I can't actually see any discernable difference beyond noise when benchmarking, although I suspect that's just because the benchmarks are too narrow to be useful. How have you been benchmarking this change, out of interest?

Regardless, I'll merge it given that I see no discernable disadvantage to this change.

@zesterer
zesterer merged commit 5f595db into zesterer:master Nov 19, 2025
3 checks passed
@fereidani

Copy link
Copy Markdown
Contributor Author

Hey, Thanks mate, I maintain another library called swait which uses unsafe RawWaker instead, it is a bit more optimized using unsafe but they are the same in methodology and they bypass Waker virtual table construction and Arc counter increment/decrement completely and this improves each call cost from 10ns to few hundred picoseconds, it is about 20x to 50x improvement based on architecture, it seems it is near 50x on apple silicon I'm not sure why but I suspect that they have slower atomics, I have some benchmark code on my repository you can take a look over there.

@zesterer

Copy link
Copy Markdown
Owner

That makes sense, thanks for clarifying.

Out of interest, have you seen my experiments on this branch?

@fereidani

Copy link
Copy Markdown
Contributor Author

Cool idea! I have seen it in https://github.com/DoumanAsh/thread-waker/blob/master/src/lib.rs , but it does not match the general performance of pollster or swait because of thread_local variable optimization. If you combine it with this method, I think it improves initialization process of the library. not sure about the performance impact, but could help the performance further through pointer indirection elimination.

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.

2 participants