From 6710856c1098f71168c47451af53bac9a33b49dd Mon Sep 17 00:00:00 2001 From: Ivan Kozik Date: Tue, 14 Jul 2020 00:12:49 +0000 Subject: Add opt-in mimalloc feature --- Cargo.lock | 28 ++++++++++++++++++++++++++++ crates/ra_prof/Cargo.toml | 2 ++ crates/ra_prof/src/lib.rs | 4 ++++ crates/rust-analyzer/Cargo.toml | 1 + xtask/src/install.rs | 16 +++++++++++++--- xtask/src/main.rs | 15 ++++++++++++--- 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c16cf4bc8..a05c62e45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -214,6 +214,15 @@ dependencies = [ "bitflags", ] +[[package]] +name = "cmake" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" +dependencies = [ + "cc", +] + [[package]] name = "console" version = "0.11.3" @@ -674,6 +683,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "libmimalloc-sys" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27252ec1d0c4e0dd6142cbc572da50b363ab56fc334f7aa8fadf295b2e24e74" +dependencies = [ + "cmake", +] + [[package]] name = "linked-hash-map" version = "0.5.3" @@ -770,6 +788,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mimalloc" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c52de2069999f01bd26436564dbe7de3a87898feeb7a0d0ff9eb20a05bb7ca0" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "miniz_oxide" version = "0.4.0" @@ -1248,6 +1275,7 @@ dependencies = [ "backtrace", "jemalloc-ctl", "jemallocator", + "mimalloc", "once_cell", "ra_arena", ] diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml index eabfcebb0..3cd8481ea 100644 --- a/crates/ra_prof/Cargo.toml +++ b/crates/ra_prof/Cargo.toml @@ -12,6 +12,7 @@ doctest = false ra_arena = { path = "../ra_arena" } once_cell = "1.3.1" backtrace = { version = "0.3.44", optional = true } +mimalloc = { version = "0.1.19", default-features = false, optional = true } [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = { version = "0.3.2", optional = true } @@ -24,4 +25,5 @@ cpu_profiler = [] # Uncomment to enable for the whole crate graph # default = [ "backtrace" ] # default = [ "jemalloc" ] +# default = [ "mimalloc" ] # default = [ "cpu_profiler" ] diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index 7163a8424..b54531b4e 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -19,6 +19,10 @@ pub use crate::{ #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; +#[cfg(all(feature = "mimalloc"))] +#[global_allocator] +static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; + /// Prints backtrace to stderr, useful for debugging. #[cfg(feature = "backtrace")] pub fn print_backtrace() { diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index c02f72517..5074740cc 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -65,3 +65,4 @@ tt = { path = "../ra_tt", package = "ra_tt" } [features] jemalloc = [ "ra_prof/jemalloc" ] +mimalloc = [ "ra_prof/mimalloc" ] diff --git a/xtask/src/install.rs b/xtask/src/install.rs index 9ba77a3aa..a0dc0c9c2 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs @@ -19,7 +19,13 @@ pub enum ClientOpt { } pub struct ServerOpt { - pub jemalloc: bool, + pub malloc: Malloc, +} + +pub enum Malloc { + System, + Jemalloc, + Mimalloc, } impl InstallCmd { @@ -130,8 +136,12 @@ fn install_server(opts: ServerOpt) -> Result<()> { ) } - let jemalloc = if opts.jemalloc { "--features jemalloc" } else { "" }; - let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", jemalloc); + let malloc_feature = match opts.malloc { + Malloc::System => "", + Malloc::Jemalloc => "--features jemalloc", + Malloc::Mimalloc => "--features mimalloc", + }; + let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", malloc_feature); if res.is_err() && old_rust { eprintln!( diff --git a/xtask/src/main.rs b/xtask/src/main.rs index f447613d4..399ff7204 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -14,7 +14,7 @@ use pico_args::Arguments; use xtask::{ codegen::{self, Mode}, dist::run_dist, - install::{ClientOpt, InstallCmd, ServerOpt}, + install::{ClientOpt, InstallCmd, Malloc, ServerOpt}, not_bash::pushd, pre_commit, project_root, release::{PromoteCmd, ReleaseCmd}, @@ -46,6 +46,7 @@ FLAGS: --client-code Install only VS Code plugin --server Install only the language server --jemalloc Use jemalloc for server + --mimalloc Use mimalloc for server -h, --help Prints help information " ); @@ -61,13 +62,21 @@ FLAGS: return Ok(()); } - let jemalloc = args.contains("--jemalloc"); + let malloc = match (args.contains("--jemalloc"), args.contains("--mimalloc")) { + (false, false) => Malloc::System, + (true, false) => Malloc::Jemalloc, + (false, true) => Malloc::Mimalloc, + (true, true) => { + eprintln!("error: Cannot use both `--jemalloc` and `--mimalloc`"); + return Ok(()); + } + }; args.finish()?; InstallCmd { client: if server { None } else { Some(ClientOpt::VsCode) }, - server: if client_code { None } else { Some(ServerOpt { jemalloc }) }, + server: if client_code { None } else { Some(ServerOpt { malloc }) }, } .run() } -- cgit v1.2.3