timer: Reduce size of Delay struct (#554)

* Remove `counted` field on `timer::Entry`.

It turns out that a better indicator of whether or not the number of
active timeouts should be decremented is if the `Entry` has been
associated with a timer. In other words, if `Entry::inner` can be
upgraded, then the count should be decremented on drop.

* timer: Tweak link between `Delay` and the driver

This tweaks the struct layout / details regarding how a `Delay` instance
is linked to a driver (timer instance). Instead of lazily allocating the
`Entry` (node shared between `Delay` and the timer), `Entry` is
allocated immediately when `Delay` is created. This allows using the
entry store data used by `Delay`.

This is in anticipation of further timer improvements that would
otherwise require the size of `Delay` to grow further. Since an
allocation is already made, the idea is to shrink the size of the
`Delay` struct.
This commit is contained in:
Carl Lerche
2018-08-21 21:48:40 -07:00
committed by GitHub
parent d822b721b4
commit cf184eb326
7 changed files with 158 additions and 139 deletions
+2 -6
View File
@@ -1,5 +1,5 @@
use {Error, Delay, Deadline, Interval};
use timer::{Registration, Inner};
use timer::Inner;
use tokio_executor::Enter;
@@ -128,11 +128,7 @@ impl Handle {
pub fn delay(&self, deadline: Instant) -> Delay {
match self.inner {
Some(ref handle_priv) => {
let registration = Registration::new_with_handle(
deadline,
handle_priv.clone());
Delay::new_with_registration(deadline, registration)
Delay::new_with_handle(deadline, handle_priv.clone())
}
None => {
Delay::new(deadline)