Add opt-in mimalloc feature

This commit is contained in:
Ivan Kozik 2020-07-14 00:12:49 +00:00
parent 46d4487b89
commit 6710856c10
6 changed files with 60 additions and 6 deletions

28
Cargo.lock generated
View file

@ -214,6 +214,15 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "cmake"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "console" name = "console"
version = "0.11.3" version = "0.11.3"
@ -674,6 +683,15 @@ dependencies = [
"winapi 0.3.9", "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]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
version = "0.5.3" version = "0.5.3"
@ -770,6 +788,15 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "mimalloc"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c52de2069999f01bd26436564dbe7de3a87898feeb7a0d0ff9eb20a05bb7ca0"
dependencies = [
"libmimalloc-sys",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.4.0" version = "0.4.0"
@ -1248,6 +1275,7 @@ dependencies = [
"backtrace", "backtrace",
"jemalloc-ctl", "jemalloc-ctl",
"jemallocator", "jemallocator",
"mimalloc",
"once_cell", "once_cell",
"ra_arena", "ra_arena",
] ]

View file

@ -12,6 +12,7 @@ doctest = false
ra_arena = { path = "../ra_arena" } ra_arena = { path = "../ra_arena" }
once_cell = "1.3.1" once_cell = "1.3.1"
backtrace = { version = "0.3.44", optional = true } backtrace = { version = "0.3.44", optional = true }
mimalloc = { version = "0.1.19", default-features = false, optional = true }
[target.'cfg(not(target_env = "msvc"))'.dependencies] [target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = { version = "0.3.2", optional = true } jemallocator = { version = "0.3.2", optional = true }
@ -24,4 +25,5 @@ cpu_profiler = []
# Uncomment to enable for the whole crate graph # Uncomment to enable for the whole crate graph
# default = [ "backtrace" ] # default = [ "backtrace" ]
# default = [ "jemalloc" ] # default = [ "jemalloc" ]
# default = [ "mimalloc" ]
# default = [ "cpu_profiler" ] # default = [ "cpu_profiler" ]

View file

@ -19,6 +19,10 @@ pub use crate::{
#[global_allocator] #[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; 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. /// Prints backtrace to stderr, useful for debugging.
#[cfg(feature = "backtrace")] #[cfg(feature = "backtrace")]
pub fn print_backtrace() { pub fn print_backtrace() {

View file

@ -65,3 +65,4 @@ tt = { path = "../ra_tt", package = "ra_tt" }
[features] [features]
jemalloc = [ "ra_prof/jemalloc" ] jemalloc = [ "ra_prof/jemalloc" ]
mimalloc = [ "ra_prof/mimalloc" ]

View file

@ -19,7 +19,13 @@ pub enum ClientOpt {
} }
pub struct ServerOpt { pub struct ServerOpt {
pub jemalloc: bool, pub malloc: Malloc,
}
pub enum Malloc {
System,
Jemalloc,
Mimalloc,
} }
impl InstallCmd { impl InstallCmd {
@ -130,8 +136,12 @@ fn install_server(opts: ServerOpt) -> Result<()> {
) )
} }
let jemalloc = if opts.jemalloc { "--features jemalloc" } else { "" }; let malloc_feature = match opts.malloc {
let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", jemalloc); 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 { if res.is_err() && old_rust {
eprintln!( eprintln!(

View file

@ -14,7 +14,7 @@ use pico_args::Arguments;
use xtask::{ use xtask::{
codegen::{self, Mode}, codegen::{self, Mode},
dist::run_dist, dist::run_dist,
install::{ClientOpt, InstallCmd, ServerOpt}, install::{ClientOpt, InstallCmd, Malloc, ServerOpt},
not_bash::pushd, not_bash::pushd,
pre_commit, project_root, pre_commit, project_root,
release::{PromoteCmd, ReleaseCmd}, release::{PromoteCmd, ReleaseCmd},
@ -46,6 +46,7 @@ FLAGS:
--client-code Install only VS Code plugin --client-code Install only VS Code plugin
--server Install only the language server --server Install only the language server
--jemalloc Use jemalloc for server --jemalloc Use jemalloc for server
--mimalloc Use mimalloc for server
-h, --help Prints help information -h, --help Prints help information
" "
); );
@ -61,13 +62,21 @@ FLAGS:
return Ok(()); 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()?; args.finish()?;
InstallCmd { InstallCmd {
client: if server { None } else { Some(ClientOpt::VsCode) }, 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() .run()
} }