From cee6975d590e2061d90a5be98d636dac044f469d Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 4 Feb 2025 00:14:12 +0000 Subject: [PATCH] Use mimalloc as memory allocator (#5378) Co-authored-by: Dessalines --- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 1 + src/lib.rs | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 776149a1d..a98908d35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3157,6 +3157,7 @@ dependencies = [ "lemmy_federate", "lemmy_routes", "lemmy_utils", + "mimalloc", "opentelemetry 0.19.0", "opentelemetry-otlp 0.12.0", "pict-rs", @@ -3266,6 +3267,16 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libmimalloc-sys" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "line-wrap" version = "0.2.0" @@ -3534,6 +3545,15 @@ dependencies = [ "quote", ] +[[package]] +name = "mimalloc" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" diff --git a/Cargo.toml b/Cargo.toml index 4aec7600e..b947c5997 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -211,6 +211,7 @@ chrono = { workspace = true } prometheus = { version = "0.13.4", features = ["process"] } serial_test = { workspace = true } clap = { workspace = true } +mimalloc = "0.1.43" actix-web-prom = "0.8.0" [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 921109ca9..f2a8786a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,6 +52,7 @@ use lemmy_utils::{ }; use prometheus::default_registry; use prometheus_metrics::serve_prometheus; +use mimalloc::MiMalloc; use reqwest_middleware::ClientBuilder; use reqwest_tracing::TracingMiddleware; use serde_json::json; @@ -64,6 +65,9 @@ use tracing_log::LogTracer; use tracing_subscriber::{filter::Targets, layer::SubscriberExt, Layer, Registry}; use url::Url; +#[global_allocator] +static GLOBAL: MiMalloc = MiMalloc; + /// Timeout for HTTP requests while sending activities. A longer timeout provides better /// compatibility with other ActivityPub software that might allocate more time for synchronous /// processing of incoming activities. This timeout should be slightly longer than the time we