summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index f607422d..d5c67a0b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,6 +19,26 @@ mod path_printer;
mod search;
mod subject;
+// Since Rust no longer uses jemalloc by default, ripgrep will, by default,
+// use the system allocator. On Linux, this would normally be glibc's
+// allocator, which is pretty good. In particular, ripgrep does not have a
+// particularly allocation heavy workload, so there really isn't much
+// difference (for ripgrep's purposes) between glibc's allocator and jemalloc.
+//
+// However, when ripgrep is built with musl, this means ripgrep will use musl's
+// allocator, which appears to be substantially worse. (musl's goal is not to
+// have the fastest version of everything. Its goal is to be small and amenable
+// to static compilation.) Even though ripgrep isn't particularly allocation
+// heavy, musl's allocator appears to slow down ripgrep quite a bit. Therefore,
+// when building with musl, we use jemalloc.
+//
+// We don't unconditionally use jemalloc because it can be nice to use the
+// system's default allocator by default. Moreover, jemalloc seems to increase
+// compilation times by a bit.
+#[cfg(target_env = "musl")]
+#[global_allocator]
+static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
+
type Result<T> = ::std::result::Result<T, Box<::std::error::Error>>;
fn main() {