From 39527f488f6514a13d0edd88a94147931ddcbb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Fri, 26 Jun 2026 15:19:15 +0800 Subject: [PATCH] perf: switch memory allocator back to jemalloc (#4084) --- .cargo/config.toml | 13 +++++++++++- .github/workflows/check.yml | 2 +- Cargo.lock | 40 +++++++++++++++++++------------------ nix/yazi-unwrapped.nix | 5 +++++ yazi-fm/Cargo.toml | 2 +- yazi-fm/src/main.rs | 2 +- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 9d806a3c..df06aa5e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,16 @@ [env] -MACOSX_DEPLOYMENT_TARGET = "10.12" +MACOSX_DEPLOYMENT_TARGET = "10.12" +JEMALLOC_SYS_WITH_LG_PAGE = "16" + +# environment variable for tikv-jemalloc-sys +# +# https://jemalloc.net/jemalloc.3.html#opt.narenas +# narenas is the maximum number of arenas to use for automatic multiplexing +# of threads and arenas. The default is four times the number of CPUs, +# or one if there is a single CPU. +# +# Improve memory efficiency by reducing fragmentation and ensuring all threads allocate from the same pool +JEMALLOC_SYS_WITH_MALLOC_CONF = "narenas:1" [target.aarch64-apple-darwin] rustflags = [ "-Ctarget-cpu=apple-m1" ] diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 77b813ee..f9412396 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -45,7 +45,7 @@ jobs: uses: mozilla-actions/sccache-action@v0.0.10 - name: Rustfmt - run: rustfmt +nightly --check **/*.rs + run: find . -name '*.rs' -not -path './target/*' -exec rustfmt +nightly --check {} + stylua: runs-on: ubuntu-22.04 diff --git a/Cargo.lock b/Cargo.lock index 2d740e82..254299f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1896,15 +1896,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" -[[package]] -name = "libmimalloc-sys" -version = "0.1.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9" -dependencies = [ - "cc", -] - [[package]] name = "libredox" version = "0.1.17" @@ -2020,15 +2011,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mimalloc" -version = "0.1.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862" -dependencies = [ - "libmimalloc-sys", -] - [[package]] name = "miniz_oxide" version = "0.8.9" @@ -3827,6 +3809,26 @@ dependencies = [ "zune-jpeg", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd8aa5b2ab86a2cefa406d889139c162cbb230092f7d1d7cbc1716405d852a3b" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0359b4327f954e0567e69fb191cf1436617748813819c94b8cd4a431422d053a" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.51" @@ -4978,12 +4980,12 @@ dependencies = [ "better-panic", "fdlimit", "libc", - "mimalloc", "mlua", "paste", "ratatui-core", "ratatui-widgets", "signal-hook-tokio", + "tikv-jemallocator", "tokio", "tokio-stream", "tracing", diff --git a/nix/yazi-unwrapped.nix b/nix/yazi-unwrapped.nix index 2c223485..2cae987c 100644 --- a/nix/yazi-unwrapped.nix +++ b/nix/yazi-unwrapped.nix @@ -7,6 +7,7 @@ installShellFiles, fetchFromGitHub, + rust-jemalloc-sys, imagemagick, }: @@ -40,6 +41,10 @@ rustPlatform.buildRustPackage (finalAttrs: { imagemagick ]; + buildInputs = [ + rust-jemalloc-sys + ]; + postInstall = '' installShellCompletion --cmd yazi \ --bash ./yazi-boot/completions/yazi.bash \ diff --git a/yazi-fm/Cargo.toml b/yazi-fm/Cargo.toml index 57bf8bb1..f8f04d3d 100644 --- a/yazi-fm/Cargo.toml +++ b/yazi-fm/Cargo.toml @@ -59,7 +59,7 @@ libc = { workspace = true } signal-hook-tokio = { version = "0.4.0", features = [ "futures-v0_3" ] } [target.'cfg(all(not(target_os = "macos"), not(target_os = "windows")))'.dependencies] -mimalloc = "0.1.52" +tikv-jemallocator = "0.6.1" [[bin]] name = "yazi" diff --git a/yazi-fm/src/main.rs b/yazi-fm/src/main.rs index 85e993d5..f6710142 100644 --- a/yazi-fm/src/main.rs +++ b/yazi-fm/src/main.rs @@ -1,6 +1,6 @@ #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] #[global_allocator] -static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; yazi_macro::mod_pub!(app cmp confirm help input mgr notify pick spot tasks which);