-
-
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
timer: introduce delay function shortcut #1440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,14 @@ pub use timer::{set_default, Timer}; | |
|
||
use std::time::{Duration, Instant}; | ||
|
||
/// Create a Future that completes at `deadline`. | ||
pub fn delay(deadline: Instant) -> Delay { | ||
Delay::new(deadline) | ||
} | ||
|
||
/// Create a Future that completes in `duration` from now. | ||
pub fn sleep(duration: Duration) -> Delay { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR, but it looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not exactly the same, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, we can keep both for now |
||
Delay::new(Instant::now() + duration) | ||
delay(Instant::now() + duration) | ||
} | ||
|
||
// ===== Internal utils ===== | ||
|
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.
Should this be tagged with
#[inline]
?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.
The compiler should be smart enough about that.
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.
Does rust do any cross-crate inlining of monomorphic functions that aren't explicitly marked whatsoever right now?
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.
According to rust-random/rand#472 (comment), it only inlines monomorphic functions only when LTO is used or it's marked explicitly. However,
Delay::new
wasn't marked inline before, so nothing has really changed, the compiler can inlineDelay::new
intodelay
inside the crate and to the outside the situation will stay the same.I created a binary crate outside of
tokio
, includedtokio-timer
, calleddelay
, compiled in release mode andobjdump
showed that the call todelay
is not inlined, butDelay::new
was inlined intodelay
. So the situation should stay as it was before with this PR.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.
We can change this in a follow up PR