-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
time: clean up redundant check in Wheel::poll() #5574
Conversation
The condition checked in the and_then() call is the same as is checked in the match below, so we can clean it up by just matching on next_expiration() directly.
also the comment looks like it referred to the code that existed before the PR that added it? https://github.com/tokio-rs/tokio/pull/2905/files#diff-f0d9f5707877769d0883b4982ca9788bd07fe6d4b7bee13549ad9ffe29475d73L141-L149 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actually equivalent? if expiration.deadline
is greater than now
, the and_then
closure returns None
, so the value of the variable expiration
is None
. in the match, if expiration
is None
, we call set_elapsed
and skip popping from the list of pending timers. after this change, the value of expiration
will now be Some
when entering the match, and we will execute a different match arm that doesn't call set_elapsed
, which changes the behavior. this doesn't seem correct to me...
oh good call my bad! |
i believe what we actually should do is remove the |
@hawkw Yeah I just messed it up here... but I think what I should have written was diff --git a/tokio/src/runtime/time/wheel/mod.rs b/tokio/src/runtime/time/wheel/mod.rs
index c3ba3643..bf13b7b2 100644
--- a/tokio/src/runtime/time/wheel/mod.rs
+++ b/tokio/src/runtime/time/wheel/mod.rs
@@ -148,23 +148,13 @@ impl Wheel {
return Some(handle);
}
- // under what circumstances is poll.expiration Some vs. None?
- let expiration = self.next_expiration().and_then(|expiration| {
- if expiration.deadline > now {
- None
- } else {
- Some(expiration)
- }
- });
-
- match expiration {
- Some(ref expiration) if expiration.deadline > now => return None,
- Some(ref expiration) => {
+ match self.next_expiration() {
+ Some(ref expiration) if expiration.deadline <= now => {
self.process_expiration(expiration);
self.set_elapsed(expiration.deadline);
}
- None => {
+ _ => {
// in this case the poll did not indicate an expiration
// _and_ we were not able to find a next expiration in
// the current list of timers. advance to the poll's
|
Hmm, that diff also doesn't look like it actually implements the current behavior, as the case where the expiration's deadline is greater than Did you mean something like this? match expiration {
Some(ref expiration) if expiration.deadline <= now => {
self.process_expiration(expiration);
self.set_elapsed(expiration.deadline);
}
_ => {
// in this case the poll did not indicate an expiration
// _and_ we were not able to find a next expiration in
// the current list of timers. advance to the poll's
// current time and do nothing else.
self.set_elapsed(now);
break;
}
} |
Ah, yup, the edit you just made to the diff looks correct --- looks like we noticed the same thing :) |
oof yeah I must be low on sleep today, updated. That's what I meant indeed :D |
@hawkw worth reopening this w/ that diff do you think? |
I think it's worth reopening, the current code is certainly a lot harder to understand than I think it needs to be (as illustrated by the amount of tries it took us to get this right...:slightly_smiling_face:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thanks for cleaning this up!
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dependencies | minor | `1.26.0` -> `1.27.0` | | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dev-dependencies | minor | `1.26.0` -> `1.27.0` | --- ### Release Notes <details> <summary>tokio-rs/tokio</summary> ### [`v1.27.0`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.27.0): Tokio v1.27.0 [Compare Source](tokio-rs/tokio@tokio-1.26.0...tokio-1.27.0) ##### 1.27.0 (March 27th, 2023) This release bumps the MSRV of Tokio to 1.56. ([#​5559]) ##### Added - io: add `async_io` helper method to sockets ([#​5512]) - io: add implementations of `AsFd`/`AsHandle`/`AsSocket` ([#​5514], [#​5540]) - net: add `UdpSocket::peek_sender()` ([#​5520]) - sync: add `RwLockWriteGuard::{downgrade_map, try_downgrade_map}` ([#​5527]) - task: add `JoinHandle::abort_handle` ([#​5543]) ##### Changed - io: use `memchr` from `libc` ([#​5558]) - macros: accept path as crate rename in `#[tokio::main]` ([#​5557]) - macros: update to syn 2.0.0 ([#​5572]) - time: don't register for a wakeup when `Interval` returns `Ready` ([#​5553]) ##### Fixed - fs: fuse std iterator in `ReadDir` ([#​5555]) - tracing: fix `spawn_blocking` location fields ([#​5573]) - time: clean up redundant check in `Wheel::poll()` ([#​5574]) ##### Documented - macros: define cancellation safety ([#​5525]) - io: add details to docs of `tokio::io::copy[_buf]` ([#​5575]) - io: refer to `ReaderStream` and `StreamReader` in module docs ([#​5576]) [#​5512]: tokio-rs/tokio#5512 [#​5514]: tokio-rs/tokio#5514 [#​5520]: tokio-rs/tokio#5520 [#​5525]: tokio-rs/tokio#5525 [#​5527]: tokio-rs/tokio#5527 [#​5540]: tokio-rs/tokio#5540 [#​5543]: tokio-rs/tokio#5543 [#​5553]: tokio-rs/tokio#5553 [#​5555]: tokio-rs/tokio#5555 [#​5557]: tokio-rs/tokio#5557 [#​5558]: tokio-rs/tokio#5558 [#​5559]: tokio-rs/tokio#5559 [#​5572]: tokio-rs/tokio#5572 [#​5573]: tokio-rs/tokio#5573 [#​5574]: tokio-rs/tokio#5574 [#​5575]: tokio-rs/tokio#5575 [#​5576]: tokio-rs/tokio#5576 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4yNC41IiwidXBkYXRlZEluVmVyIjoiMzUuMjQuNSJ9--> Co-authored-by: cabr2-bot <cabr2.help@gmail.com> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1838 Reviewed-by: crapStone <crapstone@noreply.codeberg.org> Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org> Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
The condition checked in the and_then() call is the same as is checked in the match below, so we can clean it up by just matching on next_expiration() directly.