From deed44a472edaf11d35fa98c7e68a288f8dfe93f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 22 Jul 2020 13:40:45 +0200 Subject: Remove support for jemalloc We only used it for measuring memory usage, but now we can use glibc's allocator for that just fine --- Cargo.lock | 65 ------------------------------------ crates/ra_prof/Cargo.toml | 6 ---- crates/ra_prof/src/lib.rs | 6 ---- crates/ra_prof/src/memory_usage.rs | 10 ++---- crates/rust-analyzer/Cargo.toml | 1 - crates/rust-analyzer/src/bin/args.rs | 4 +-- docs/dev/README.md | 8 +---- xtask/src/dist.rs | 2 -- xtask/src/install.rs | 2 -- xtask/src/main.rs | 12 ++----- 10 files changed, 7 insertions(+), 109 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a8271f09..62fd9bfb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -359,12 +359,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "fs_extra" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" - [[package]] name = "fsevent" version = "2.0.2" @@ -541,38 +535,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" -[[package]] -name = "jemalloc-ctl" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" -dependencies = [ - "jemalloc-sys", - "libc", - "paste", -] - -[[package]] -name = "jemalloc-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" -dependencies = [ - "cc", - "fs_extra", - "libc", -] - -[[package]] -name = "jemallocator" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" -dependencies = [ - "jemalloc-sys", - "libc", -] - [[package]] name = "jod-thread" version = "0.1.2" @@ -874,25 +836,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "paste" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" -dependencies = [ - "paste-impl", - "proc-macro-hack", -] - -[[package]] -name = "paste-impl" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" -dependencies = [ - "proc-macro-hack", -] - [[package]] name = "paths" version = "0.1.0" @@ -931,12 +874,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" -[[package]] -name = "proc-macro-hack" -version = "0.5.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" - [[package]] name = "proc-macro2" version = "1.0.19" @@ -1199,8 +1136,6 @@ version = "0.1.0" dependencies = [ "backtrace", "cfg-if", - "jemalloc-ctl", - "jemallocator", "libc", "mimalloc", "once_cell", diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml index 2e60858f1..84d895317 100644 --- a/crates/ra_prof/Cargo.toml +++ b/crates/ra_prof/Cargo.toml @@ -17,16 +17,10 @@ mimalloc = { version = "0.1.19", default-features = false, optional = true } cfg-if = "0.1.10" libc = "0.2.73" -[target.'cfg(not(target_env = "msvc"))'.dependencies] -jemallocator = { version = "0.3.2", optional = true } -jemalloc-ctl = { version = "0.3.3", optional = true } - [features] -jemalloc = [ "jemallocator", "jemalloc-ctl" ] 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 b54531b4e..a5b408a1d 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -13,12 +13,6 @@ pub use crate::{ memory_usage::{Bytes, MemoryUsage}, }; -// We use jemalloc mainly to get heap usage statistics, actual performance -// difference is not measures. -#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] -#[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; - #[cfg(all(feature = "mimalloc"))] #[global_allocator] static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/crates/ra_prof/src/memory_usage.rs b/crates/ra_prof/src/memory_usage.rs index b1858b06f..ee79ec3ee 100644 --- a/crates/ra_prof/src/memory_usage.rs +++ b/crates/ra_prof/src/memory_usage.rs @@ -1,7 +1,7 @@ //! FIXME: write short doc here +use std::fmt; use cfg_if::cfg_if; -use std::fmt; pub struct MemoryUsage { pub allocated: Bytes, @@ -11,13 +11,7 @@ pub struct MemoryUsage { impl MemoryUsage { pub fn current() -> MemoryUsage { cfg_if! { - if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] { - jemalloc_ctl::epoch::advance().unwrap(); - MemoryUsage { - allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()), - resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()), - } - } else if #[cfg(target_os = "linux")] { + if #[cfg(target_os = "linux")] { // Note: This is incredibly slow. let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as usize; MemoryUsage { allocated: Bytes(alloc), resident: Bytes(0) } diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 5eb2d0bb7..215eeb2f6 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -64,5 +64,4 @@ mbe = { path = "../ra_mbe", package = "ra_mbe" } tt = { path = "../ra_tt", package = "ra_tt" } [features] -jemalloc = [ "ra_prof/jemalloc" ] mimalloc = [ "ra_prof/mimalloc" ] diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index 3210416ee..741a2a951 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs @@ -166,7 +166,7 @@ USAGE: FLAGS: -o, --only Only analyze items matching this path -h, --help Prints help information - --memory-usage Collect memory usage statistics (requires `--features jemalloc`) + --memory-usage Collect memory usage statistics --randomize Randomize order in which crates, modules, and items are processed --parallel Run type inference in parallel --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis @@ -221,7 +221,7 @@ USAGE: FLAGS: -h, --help Prints help information - --memory-usage Collect memory usage statistics (requires `--features jemalloc`) + --memory-usage Collect memory usage statistics --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding -v, --verbose diff --git a/docs/dev/README.md b/docs/dev/README.md index 3af01cd6b..2bb2f75bd 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md @@ -397,13 +397,7 @@ To log all communication between the server and the client, there are two choice There are also two VS Code commands which might be of interest: -* `Rust Analyzer: Status` shows some memory-usage statistics. To take full - advantage of it, you need to compile rust-analyzer with jemalloc support: - ``` - $ cargo install --path crates/rust-analyzer --force --features jemalloc - ``` - - There's an alias for this: `cargo xtask install --server --jemalloc`. +* `Rust Analyzer: Status` shows some memory-usage statistics. * `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection. diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index b8f68027c..c198c0907 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -57,8 +57,6 @@ fn dist_server() -> Result<()> { env::set_var("CC", "clang"); run!( "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" - // We'd want to add, but that requires setting the right linker somehow - // --features=jemalloc )?; } else { run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; diff --git a/xtask/src/install.rs b/xtask/src/install.rs index a0dc0c9c2..b25a6e301 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs @@ -24,7 +24,6 @@ pub struct ServerOpt { pub enum Malloc { System, - Jemalloc, Mimalloc, } @@ -138,7 +137,6 @@ fn install_server(opts: ServerOpt) -> Result<()> { 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); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 399ff7204..53d3ce3e7 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -45,7 +45,6 @@ USAGE: 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 " @@ -62,15 +61,8 @@ FLAGS: return Ok(()); } - 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(()); - } - }; + let malloc = + if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; args.finish()?; -- cgit v1.2.3 From 9ad41eb9085cd7ceaf479f659a7071df81059b7c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 22 Jul 2020 13:42:53 +0200 Subject: Setup global allocator in the correct crate It worked before, but was roundabout --- Cargo.lock | 2 +- crates/ra_prof/Cargo.toml | 2 -- crates/ra_prof/src/lib.rs | 4 ---- crates/rust-analyzer/Cargo.toml | 4 +--- crates/rust-analyzer/src/bin/main.rs | 4 ++++ 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62fd9bfb6..280d97432 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1137,7 +1137,6 @@ dependencies = [ "backtrace", "cfg-if", "libc", - "mimalloc", "once_cell", "ra_arena", ] @@ -1362,6 +1361,7 @@ dependencies = [ "log", "lsp-server", "lsp-types", + "mimalloc", "parking_lot", "pico-args", "ra_cfg", diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml index 84d895317..6c214501e 100644 --- a/crates/ra_prof/Cargo.toml +++ b/crates/ra_prof/Cargo.toml @@ -13,7 +13,6 @@ 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 } cfg-if = "0.1.10" libc = "0.2.73" @@ -22,5 +21,4 @@ cpu_profiler = [] # Uncomment to enable for the whole crate graph # default = [ "backtrace" ] -# default = [ "mimalloc" ] # default = [ "cpu_profiler" ] diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index a5b408a1d..ba5609703 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -13,10 +13,6 @@ pub use crate::{ memory_usage::{Bytes, MemoryUsage}, }; -#[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 215eeb2f6..023c104d1 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -29,6 +29,7 @@ serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.48" threadpool = "1.7.1" rayon = "1.3.1" +mimalloc = { version = "0.1.19", default-features = false, optional = true } stdx = { path = "../stdx" } @@ -62,6 +63,3 @@ expect = { path = "../expect" } test_utils = { path = "../test_utils" } mbe = { path = "../ra_mbe", package = "ra_mbe" } tt = { path = "../ra_tt", package = "ra_tt" } - -[features] -mimalloc = [ "ra_prof/mimalloc" ] diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 408892eab..a473c9165 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -16,6 +16,10 @@ use vfs::AbsPathBuf; use crate::args::HelpPrinted; +#[cfg(all(feature = "mimalloc"))] +#[global_allocator] +static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; + fn main() -> Result<()> { setup_logging()?; let args = match args::Args::parse()? { -- cgit v1.2.3