diff --git a/Cargo.lock b/Cargo.lock index d88e65f9..a251a2a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -615,6 +615,7 @@ dependencies = [ "indicatif", "interprocess", "jsonc-parser", + "mimalloc", "predicates", "rayon", "regex", @@ -1906,6 +1907,15 @@ version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +[[package]] +name = "libmimalloc-sys" +version = "0.1.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9" +dependencies = [ + "cc", +] + [[package]] name = "libsqlite3-sys" version = "0.38.2" @@ -1968,6 +1978,15 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" +[[package]] +name = "mimalloc" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.17" diff --git a/README.md b/README.md index 389a9dbd..134f01a0 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,9 @@ GitHub Releases publish these archive families: | Windows x86_64 | `x86_64-pc-windows-msvc` | `.zip` | | Windows ARM64 | `aarch64-pc-windows-msvc` | `.zip` | +The Linux archives are static musl builds that allocate through mimalloc; the +macOS and Windows archives use the platform allocator. + Each release also includes `SHA256SUMS`. GitHub CLI users can additionally verify an archive's build provenance: diff --git a/crates/codegraph-cli/Cargo.toml b/crates/codegraph-cli/Cargo.toml index fee53a8e..17876ad6 100644 --- a/crates/codegraph-cli/Cargo.toml +++ b/crates/codegraph-cli/Cargo.toml @@ -44,6 +44,11 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } time = { workspace = true } +# musl's allocator serializes threads; the static Linux release builds use +# mimalloc instead. Other targets keep their system allocator. +[target.'cfg(target_env = "musl")'.dependencies] +mimalloc = { version = "0.1.52", default-features = false, features = ["v2"] } + [dev-dependencies] rusqlite = { workspace = true } codegraph-bench = { path = "../codegraph-bench" } diff --git a/crates/codegraph-cli/src/main.rs b/crates/codegraph-cli/src/main.rs index 310f49a7..e0b2c167 100644 --- a/crates/codegraph-cli/src/main.rs +++ b/crates/codegraph-cli/src/main.rs @@ -42,6 +42,13 @@ mod installer; mod structural_gate; mod viewer_gate; +/// musl's allocator serializes threads, so the static Linux release builds got +/// slower as threads were added: a full index of this repository took over two +/// minutes at 32 threads, against 51 s at one. Through mimalloc it takes 8 s. +#[cfg(target_env = "musl")] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + /// Test-only: the ONE process-wide environment lock for this binary. /// /// `cargo test` runs every unit test of this binary on threads of a SINGLE diff --git a/docs/readme/README.zh-CN.md b/docs/readme/README.zh-CN.md index 0f3154ad..9825c256 100644 --- a/docs/readme/README.zh-CN.md +++ b/docs/readme/README.zh-CN.md @@ -76,6 +76,8 @@ GitHub Releases 发布以下归档系列: | Windows x86_64 | `x86_64-pc-windows-msvc` | `.zip` | | Windows ARM64 | `aarch64-pc-windows-msvc` | `.zip` | +Linux 归档是静态链接的 musl 构建,内存分配走 mimalloc;macOS 与 Windows 归档使用系统分配器。 + 每个 Release 还包含 `SHA256SUMS`。GitHub CLI 用户可进一步验证归档构建来源: ```bash