From f354cd50fff0a43580fac4d4df5c9740f25534ef Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Sat, 26 Feb 2022 12:07:35 -0500 Subject: [PATCH] perf: use mimalloc --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ Cargo.lock | 25 +++++++++++++++++++++++++ src/alejandra_engine/Cargo.toml | 18 ++++++++++++++++++ src/alejandra_engine/src/lib.rs | 29 +++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e5c83..343350a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,33 @@ Types of changes - Security in case of vulnerabilities. --> +### Changed + +- Linux binaries now use [mimalloc](https://github.com/microsoft/mimalloc) + to provide much better performance when formatting Nixpkgs: + + - x86_64-unknown-linux-gnu, 1.3x faster, + from 0m10.639s to 0m8.381s + + - x86_64-unknown-linux-musl, 15.8x faster, + from 2m32.686s to 0m9.642s + + - [On QEMU](https://www.qemu.org/) aarch64-unknown-linux-musl, + 4.6x faster, + from 5m26s to 1m10s + + - [On QEMU](https://www.qemu.org/) armv6l-unknown-linux-musleabihf, + 1.05x faster, + from 8m7s to 7m41s + + - [On QEMU](https://www.qemu.org/) armv7l-unknown-linux-musleabihf, + 1.15x faster, + from 5m54s to 5m7s + + - [On QEMU](https://www.qemu.org/) i686-unknown-linux-musl, + 1.07x faster, + from 2m44s to 2m33s + ## [0.6.0] - 2022-02-25 ### Added diff --git a/Cargo.lock b/Cargo.lock index 4e607b1..5d82f15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,7 @@ dependencies = [ name = "alejandra_engine" version = "0.6.0" dependencies = [ + "mimalloc", "rnix", "rowan", ] @@ -62,6 +63,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + [[package]] name = "cfg-if" version = "1.0.0" @@ -191,6 +198,15 @@ version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +[[package]] +name = "libmimalloc-sys" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7705fc40f6ed493f73584abbb324e74f96b358ff60dfe5659a0f8fc12c590a69" +dependencies = [ + "cc", +] + [[package]] name = "memchr" version = "2.4.1" @@ -206,6 +222,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mimalloc" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0dfa131390c2f6bdb3242f65ff271fcdaca5ff7b6c08f28398be7f2280e3926" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "num-traits" version = "0.2.14" diff --git a/src/alejandra_engine/Cargo.toml b/src/alejandra_engine/Cargo.toml index 7515e97..77fa3f6 100644 --- a/src/alejandra_engine/Cargo.toml +++ b/src/alejandra_engine/Cargo.toml @@ -2,6 +2,24 @@ rnix = "*" rowan = "0.12.6" # follows rnix +[target.aarch64-unknown-linux-musl.dependencies] +mimalloc = { version = "*", default-features = false } + +[target.armv6l-unknown-linux-musleabihf.dependencies] +mimalloc = { version = "*", default-features = false } + +[target.armv7l-unknown-linux-musleabihf.dependencies] +mimalloc = { version = "*", default-features = false } + +[target.i686-unknown-linux-musl.dependencies] +mimalloc = { version = "*", default-features = false } + +[target.x86_64-unknown-linux-gnu.dependencies] +mimalloc = { version = "*", default-features = false } + +[target.x86_64-unknown-linux-musl.dependencies] +mimalloc = { version = "*", default-features = false } + [package] authors = ["Kevin Amado "] description = "The Uncompromising Nix Code Formatter" diff --git a/src/alejandra_engine/src/lib.rs b/src/alejandra_engine/src/lib.rs index d77ba86..f1262b1 100644 --- a/src/alejandra_engine/src/lib.rs +++ b/src/alejandra_engine/src/lib.rs @@ -1,3 +1,32 @@ +#[cfg(any( + all( + target_arch = "aarch64", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + ), + all( + any(target_arch = "armv6l", target_arch = "armv7l",), + target_vendor = "unknown", + target_os = "linux", + target_env = "musleabihf" + ), + all( + target_arch = "i686", + target_vendor = "unknown", + target_os = "linux", + target_env = "musl" + ), + all( + target_arch = "x86_64", + target_vendor = "unknown", + target_os = "linux", + any(target_env = "gnu", target_env = "musl") + ), +))] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + pub(crate) mod builder; pub(crate) mod children; pub mod format;