From 9271b95c87d71d1c1b5539261db51e0ec4e53aee Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Wed, 17 Jul 2019 00:29:22 -0400 Subject: [PATCH] Avoid a copy of the Future when initializing the Box. (#29) Future's can be pretty big (> 1500 bytes) so this probably worth doing. I confirmed with memcpy-find that this did infact eliminate two ~1500 byte copies from the actix-web basic example. --- actix-rt/Cargo.toml | 1 + actix-rt/src/arbiter.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index d00346f3..a059c6e0 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -24,3 +24,4 @@ tokio-current-thread = "0.1" tokio-executor = "0.1.5" tokio-reactor = "0.1.7" tokio-timer = "0.2.8" +copyless = "0.1.4" diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs index 0fba710c..b7cdca0a 100644 --- a/actix-rt/src/arbiter.rs +++ b/actix-rt/src/arbiter.rs @@ -11,6 +11,8 @@ use tokio_current_thread::spawn; use crate::builder::Builder; use crate::system::System; +use copyless::BoxHelper; + thread_local!( static ADDR: RefCell> = RefCell::new(None); static RUNNING: Cell = Cell::new(false); @@ -141,9 +143,9 @@ impl Arbiter { { RUNNING.with(move |cell| { if cell.get() { - spawn(Box::new(future)); + spawn(Box::alloc().init(future)); } else { - Q.with(move |cell| cell.borrow_mut().push(Box::new(future))); + Q.with(move |cell| cell.borrow_mut().push(Box::alloc().init(future))); } }); }