mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
perf(ext/http): faster is_content_compressible (#14383)
Cleanup + benches
This commit is contained in:
parent
8107a79b39
commit
e2fba7b967
5 changed files with 687 additions and 641 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -966,6 +966,7 @@ version = "0.43.0"
|
|||
dependencies = [
|
||||
"async-compression",
|
||||
"base64 0.13.0",
|
||||
"bencher",
|
||||
"brotli",
|
||||
"bytes",
|
||||
"cache_control",
|
||||
|
@ -976,6 +977,7 @@ dependencies = [
|
|||
"hyper",
|
||||
"mime",
|
||||
"percent-encoding",
|
||||
"phf",
|
||||
"ring",
|
||||
"serde",
|
||||
"tokio",
|
||||
|
|
|
@ -13,6 +13,10 @@ description = "HTTP server implementation for Deno"
|
|||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[[bench]]
|
||||
name = "compressible"
|
||||
harness = false
|
||||
|
||||
[dependencies]
|
||||
async-compression = { version = "0.3.1", features = ["tokio", "brotli", "gzip"] }
|
||||
base64 = "0.13.0"
|
||||
|
@ -26,7 +30,11 @@ fly-accept-encoding = "0.2.0-alpha.5"
|
|||
hyper = { version = "0.14.9", features = ["server", "stream", "http1", "http2", "runtime"] }
|
||||
mime = "0.3.16"
|
||||
percent-encoding = "2.1.0"
|
||||
phf = { version = "0.10", features = ["macros"] }
|
||||
ring = "0.16.20"
|
||||
serde = { version = "1.0.129", features = ["derive"] }
|
||||
tokio = { version = "1.17", features = ["full"] }
|
||||
tokio-util = { version = "0.7.0", features = ["io"] }
|
||||
|
||||
[dev-dependencies]
|
||||
bencher = "0.1"
|
||||
|
|
37
ext/http/benches/compressible.rs
Normal file
37
ext/http/benches/compressible.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
||||
use deno_http::compressible::is_content_compressible;
|
||||
|
||||
fn compressible_simple_hit(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
is_content_compressible("text/plain");
|
||||
})
|
||||
}
|
||||
|
||||
fn compressible_complex_hit(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
is_content_compressible("text/PlAIn; charset=utf-8");
|
||||
})
|
||||
}
|
||||
|
||||
fn compressible_simple_miss(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
is_content_compressible("text/fake");
|
||||
})
|
||||
}
|
||||
|
||||
fn compressible_complex_miss(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
is_content_compressible("text/fake;charset=utf-8");
|
||||
})
|
||||
}
|
||||
|
||||
benchmark_group!(
|
||||
benches,
|
||||
compressible_simple_hit,
|
||||
compressible_complex_hit,
|
||||
compressible_simple_miss,
|
||||
compressible_complex_miss,
|
||||
);
|
||||
|
||||
benchmark_main!(benches);
|
File diff suppressed because it is too large
Load diff
|
@ -65,7 +65,7 @@ use tokio::io::AsyncWriteExt;
|
|||
use tokio::task::spawn_local;
|
||||
use tokio_util::io::ReaderStream;
|
||||
|
||||
mod compressible;
|
||||
pub mod compressible;
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder()
|
||||
|
@ -542,8 +542,9 @@ async fn op_http_write_headers(
|
|||
}
|
||||
|
||||
if headers_allow_compression {
|
||||
body_compressible =
|
||||
compressible::is_content_compressible(content_type_header);
|
||||
body_compressible = content_type_header
|
||||
.map(compressible::is_content_compressible)
|
||||
.unwrap_or_default();
|
||||
}
|
||||
|
||||
let body: Response<Body>;
|
||||
|
|
Loading…
Reference in a new issue