From 1d0a47460dc356ffe4ab386cb9a44acbe7e5aa4d 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 79896704a..a51c63436 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2832,6 +2832,7 @@ dependencies = [ "lemmy_federate", "lemmy_routes", "lemmy_utils", + "mimalloc", "reqwest-middleware", "reqwest-tracing", "rustls 0.23.21", @@ -2935,6 +2936,16 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[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 = "linked-hash-map" version = "0.5.6" @@ -3225,6 +3236,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 6a33825c2..7d5acc7ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -180,3 +180,4 @@ serde_json = { workspace = true } rustls = { workspace = true } tokio.workspace = true clap = { workspace = true } +mimalloc = "0.1.43" diff --git a/src/lib.rs b/src/lib.rs index b7995e47c..6c660175b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,6 +52,7 @@ use lemmy_utils::{ settings::{structs::Settings, SETTINGS}, VERSION, }; +use mimalloc::MiMalloc; use reqwest_middleware::ClientBuilder; use reqwest_tracing::TracingMiddleware; use serde_json::json; @@ -59,6 +60,9 @@ use std::{ops::Deref, time::Duration}; use tokio::signal::unix::SignalKind; use tracing_actix_web::{DefaultRootSpanBuilder, TracingLogger}; +#[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