From 7795a1a532c03e6e279667d364cc27755ddf2b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Fri, 3 May 2024 22:38:25 +0200 Subject: [PATCH] Make mimalloc optional for udp and http --- crates/http/Cargo.toml | 10 ++++++++-- crates/http/src/main.rs | 1 + crates/udp/Cargo.toml | 10 ++++++++-- crates/udp/src/main.rs | 1 + crates/ws/Cargo.toml | 4 +++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/http/Cargo.toml b/crates/http/Cargo.toml index 5cbd14d..e1d7f4f 100644 --- a/crates/http/Cargo.toml +++ b/crates/http/Cargo.toml @@ -18,9 +18,13 @@ name = "aquatic_http" name = "aquatic_http" [features] -default = ["prometheus"] +default = ["prometheus", "mimalloc"] prometheus = ["aquatic_common/prometheus", "metrics", "dep:metrics-util"] metrics = ["dep:metrics"] +# Use mimalloc allocator for much better performance. +# +# Requires cmake and a C compiler +mimalloc = ["dep:mimalloc"] [dependencies] aquatic_common = { workspace = true, features = ["rustls"] } @@ -40,7 +44,6 @@ httparse = "1" itoa = "1" libc = "0.2" log = "0.4" -mimalloc = { version = "0.1", default-features = false } memchr = "2" privdrop = "0.5" once_cell = "1" @@ -56,6 +59,9 @@ thiserror = "1" metrics = { version = "0.22", optional = true } metrics-util = { version = "0.16", optional = true } +# mimalloc feature +mimalloc = { version = "0.1", default-features = false, optional = true } + [dev-dependencies] quickcheck = "1" quickcheck_macros = "1" diff --git a/crates/http/src/main.rs b/crates/http/src/main.rs index 7f40c2c..bbea551 100644 --- a/crates/http/src/main.rs +++ b/crates/http/src/main.rs @@ -1,6 +1,7 @@ use aquatic_common::cli::run_app_with_cli_and_config; use aquatic_http::config::Config; +#[cfg(feature = "mimalloc")] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/crates/udp/Cargo.toml b/crates/udp/Cargo.toml index 47cfa06..d873087 100644 --- a/crates/udp/Cargo.toml +++ b/crates/udp/Cargo.toml @@ -18,13 +18,17 @@ name = "aquatic_udp" name = "aquatic_udp" [features] -default = ["prometheus"] +default = ["prometheus", "mimalloc"] # Export prometheus metrics prometheus = ["metrics", "aquatic_common/prometheus"] # Experimental io_uring support (Linux 6.0 or later required) io-uring = ["dep:io-uring"] # Experimental CPU pinning support cpu-pinning = ["aquatic_common/cpu-pinning"] +# Use mimalloc allocator for much better performance. +# +# Requires cmake and a C compiler +mimalloc = ["dep:mimalloc"] [dependencies] aquatic_common.workspace = true @@ -45,7 +49,6 @@ hdrhistogram = "7" hex = "0.4" libc = "0.2" log = "0.4" -mimalloc = { version = "0.1", default-features = false } mio = { version = "0.8", features = ["net", "os-poll"] } num-format = "0.4" parking_lot = "0.12" @@ -63,6 +66,9 @@ metrics = { version = "0.22", optional = true } # io-uring feature io-uring = { version = "0.6", optional = true } +# mimalloc feature +mimalloc = { version = "0.1", default-features = false, optional = true } + [dev-dependencies] tempfile = "3" quickcheck = "1" diff --git a/crates/udp/src/main.rs b/crates/udp/src/main.rs index 9ec75cc..7dab664 100644 --- a/crates/udp/src/main.rs +++ b/crates/udp/src/main.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "mimalloc")] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/crates/ws/Cargo.toml b/crates/ws/Cargo.toml index 59bb1bc..064bea0 100644 --- a/crates/ws/Cargo.toml +++ b/crates/ws/Cargo.toml @@ -44,7 +44,6 @@ hashbrown = { version = "0.14", features = ["serde"] } httparse = "1" indexmap = "2" log = "0.4" -mimalloc = { version = "0.1", default-features = false, optional = true } privdrop = "0.5" rand = { version = "0.8", features = ["small_rng"] } rustls = "0.23" @@ -60,6 +59,9 @@ tungstenite = "0.21" metrics = { version = "0.22", optional = true } metrics-util = { version = "0.16", optional = true } +# mimalloc feature +mimalloc = { version = "0.1", default-features = false, optional = true } + [dev-dependencies] quickcheck = "1" quickcheck_macros = "1"