Skip to content

Commit

Permalink
enable jemalloc only on 64-bit musl
Browse files Browse the repository at this point in the history
I don't know why fd was disabling jemalloc on musl, when that's the libc
where jemalloc really helps (about 3.6x faster than the default malloc
on musl 1.2.2). On glibc 2.33 (arch) and 2.28 (buster), jemalloc is only
2-3% faster than the default allocator, which isn't worth the extra
compile time.

Hyperfine runs searching in a linux kernel checkout where the Arch
5.12.15 config has been compiled on an i7-7700K running at stock speeds.

glibc:
    Benchmark #1: ./fd.gnu-default asdfasdfasdfasdf /workspace/linux-mainline
      Time (mean ± σ):      83.4 ms ±   2.9 ms    [User: 506.0 ms, System: 106.3 ms]
      Range (min … max):    79.8 ms … 111.6 ms    500 runs

    Benchmark #2: ./fd.gnu-jemalloc asdfasdfasdfasdf /workspace/linux-mainline
      Time (mean ± σ):      81.1 ms ±   3.1 ms    [User: 483.4 ms, System: 103.5 ms]
      Range (min … max):    77.6 ms … 118.3 ms    500 runs

    Summary
      './fd.gnu-jemalloc asdfasdfasdfasdf /workspace/linux-mainline' ran
	1.03 ± 0.05 times faster than './fd.gnu-default asdfasdfasdfasdf /workspace/linux-mainline'

musl:
    Benchmark #1: ./fd.musl-default asdfasdfasdfasdf /workspace/linux-mainline
      Time (mean ± σ):     274.0 ms ±   3.8 ms    [User: 2.040 s, System: 0.069 s]
      Range (min … max):   266.7 ms … 305.9 ms    500 runs

    Benchmark #2: ./fd.musl-jemalloc asdfasdfasdfasdf /workspace/linux-mainline
      Time (mean ± σ):      76.1 ms ±   3.8 ms    [User: 480.4 ms, System: 71.6 ms]
      Range (min … max):    72.1 ms … 112.1 ms    500 runs

    Summary
      './fd.musl-jemalloc asdfasdfasdfasdf /workspace/linux-mainline' ran
	3.60 ± 0.18 times faster than './fd.musl-default asdfasdfasdfasdf /workspace/linux-mainline'
  • Loading branch information
aswild committed Jul 10, 2021
1 parent 6a19842 commit 87bafc7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ users = "0.11.0"
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
libc = "0.2"

# FIXME: Re-enable jemalloc on macOS
# jemalloc is currently disabled on macOS due to a bug in jemalloc in combination with macOS
# Catalina. See https://github.com/sharkdp/fd/issues/498 for details.
[target.'cfg(all(not(windows), not(target_os = "android"), not(target_os = "macos"), not(target_env = "musl")))'.dependencies]
[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies]
jemallocator = "0.3.0"

[dev-dependencies]
Expand Down
9 changes: 1 addition & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ use crate::filter::{SizeFilter, TimeFilter};
use crate::options::Options;
use crate::regex_helper::{pattern_has_uppercase_char, pattern_matches_strings_with_leading_dot};

// We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/481
// FIXME: re-enable jemalloc on macOS, see comment in Cargo.toml file for more infos
#[cfg(all(
not(windows),
not(target_os = "android"),
not(target_os = "macos"),
not(target_env = "musl")
))]
#[cfg(all(target_env = "musl", target_pointer_width = "64"))]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

Expand Down

0 comments on commit 87bafc7

Please sign in to comment.