1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 15:42:57 +01:00

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.
This commit is contained in:
Jeff Muizelaar 2019-07-17 00:29:22 -04:00 committed by Nikolay Kim
parent 1b3cd0d88c
commit 9271b95c87
2 changed files with 5 additions and 2 deletions

View File

@ -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"

View File

@ -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<Option<Arbiter>> = RefCell::new(None);
static RUNNING: Cell<bool> = 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)));
}
});
}