From 6e7d36cffcbfbc9388dc63accb719a9b514b4011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 7 Jan 2024 10:41:11 +0100 Subject: [PATCH] ws: add mimalloc feature to make it easier to disable it --- TODO.md | 1 - crates/ws/Cargo.toml | 7 +++++-- crates/ws/src/main.rs | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 7b61f97..927ff8b 100644 --- a/TODO.md +++ b/TODO.md @@ -6,7 +6,6 @@ interval to clean up data. should more or less fix prometheus memory leak * ws - * mimalloc feature, same for http * try replacing race with futures::future::select * bug report for glommio regarding memory leak diff --git a/crates/ws/Cargo.toml b/crates/ws/Cargo.toml index 6f4f7b1..662bc61 100644 --- a/crates/ws/Cargo.toml +++ b/crates/ws/Cargo.toml @@ -18,9 +18,12 @@ name = "aquatic_ws" name = "aquatic_ws" [features] -default = ["prometheus"] +default = ["prometheus", "mimalloc"] prometheus = ["metrics", "metrics-exporter-prometheus"] metrics = ["dep:metrics", "metrics-util"] +# Use mimalloc allocator for much better performance. Requires cmake and a +# C/C++ compiler +mimalloc = ["dep:mimalloc"] [dependencies] aquatic_common = { workspace = true, features = ["rustls", "glommio"] } @@ -43,7 +46,7 @@ log = "0.4" metrics = { version = "0.22", optional = true } metrics-util = { version = "0.16", optional = true } metrics-exporter-prometheus = { version = "0.13", optional = true, default-features = false, features = ["http-listener"] } -mimalloc = { version = "0.1", default-features = false } +mimalloc = { version = "0.1", default-features = false, optional = true } privdrop = "0.5" rand = { version = "0.8", features = ["small_rng"] } rustls = "0.22" diff --git a/crates/ws/src/main.rs b/crates/ws/src/main.rs index b214a47..0a39f95 100644 --- a/crates/ws/src/main.rs +++ b/crates/ws/src/main.rs @@ -1,8 +1,9 @@ use aquatic_common::cli::run_app_with_cli_and_config; use aquatic_ws::config::Config; -// #[global_allocator] -// static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; +#[cfg(feature = "mimalloc")] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; fn main() { run_app_with_cli_and_config::(