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

Avoid creating Delay multiple times #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AnthonyMikh
Copy link

Creating a Delay is a relatively heavy operation which involves creating two mutexes and an Arc, so it makes sense to avoid calling Delay::new repeatedly. In this change I introduced a new boolean field which tracks if clock is actually used, and instead of creating a new Delay from scratch I call Delay::reset on existing one if possible. This should help with performance in scenarios when buffered items are more often yielded by timeout rather than hitting maximum capacity.

(BTW I do not understand why clock is pinned since Delay is Unpin anyway. Is it an oversight?)

@mre
Copy link
Owner

mre commented May 10, 2024

Sorry, was playing around with benchmarks and accidentally pushed to your branch. Moved the commits to a separate branch now. #26

I think we should run the benchmarks to see if the change makes a difference. Feel free to try it on your local machine by running cargo bench on master and your branch.
There should also be an automatic GitHub action being triggered when you push to this branch again. (Although I'm not 100% convinced that we'll keep it, as it might lead to false-positives.)

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

2 participants