From 3b897da8e25f7b09b8e56eb1c022df1e16279478 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 28 Mar 2019 21:15:26 -0700 Subject: [PATCH] Do not use thread pool for decomression if chunk size is smaller than 2048 --- actix-http/CHANGES.md | 7 +++++++ actix-http/Cargo.toml | 2 +- actix-http/src/encoding/decoder.rs | 26 ++++++++++++++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 95ec1c35f..e95963496 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.1.0-alpha.2] - 2019-xx-xx + +### Changed + +* Do not use thread pool for decomression if chunk size is smaller than 2048. + + ## [0.1.0-alpha.1] - 2019-03-28 * Initial impl diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 9734bd1a6..180cda787 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http" -version = "0.1.0-alpha.1" +version = "0.1.0-alpha.2" authors = ["Nikolay Kim "] description = "Actix http primitives" readme = "README.md" diff --git a/actix-http/src/encoding/decoder.rs b/actix-http/src/encoding/decoder.rs index ae2b4ae6b..16d15e905 100644 --- a/actix-http/src/encoding/decoder.rs +++ b/actix-http/src/encoding/decoder.rs @@ -12,6 +12,8 @@ use super::Writer; use crate::error::PayloadError; use crate::http::header::{ContentEncoding, HeaderMap, CONTENT_ENCODING}; +const INPLACE: usize = 2049; + pub struct Decoder { decoder: Option, stream: S, @@ -92,10 +94,18 @@ where match self.stream.poll()? { Async::Ready(Some(chunk)) => { if let Some(mut decoder) = self.decoder.take() { - self.fut = Some(run(move || { + if chunk.len() < INPLACE { let chunk = decoder.feed_data(chunk)?; - Ok((chunk, decoder)) - })); + self.decoder = Some(decoder); + if let Some(chunk) = chunk { + return Ok(Async::Ready(Some(chunk))); + } + } else { + self.fut = Some(run(move || { + let chunk = decoder.feed_data(chunk)?; + Ok((chunk, decoder)) + })); + } continue; } else { return Ok(Async::Ready(Some(chunk))); @@ -103,14 +113,10 @@ where } Async::Ready(None) => { self.eof = true; - if let Some(mut decoder) = self.decoder.take() { - self.fut = Some(run(move || { - let chunk = decoder.feed_eof()?; - Ok((chunk, decoder)) - })); - continue; + return if let Some(mut decoder) = self.decoder.take() { + Ok(Async::Ready(decoder.feed_eof()?)) } else { - return Ok(Async::Ready(None)); + Ok(Async::Ready(None)) }; } Async::NotReady => break,