aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-01-18 18:25:55 +0000
committerJonas Schievink <[email protected]>2021-01-18 18:39:46 +0000
commit9b5fa1c61a85972da419aa29d61286cb9e268f83 (patch)
tree29704f0e4140261ed68bb5ea3cf52e7385bfc997
parent6764d790ac904533dc7618fd38724a135499f87c (diff)
Add back jemalloc support
-rw-r--r--Cargo.lock65
-rw-r--r--crates/profile/Cargo.toml2
-rw-r--r--crates/profile/src/memory_usage.rs7
-rw-r--r--crates/rust-analyzer/Cargo.toml6
-rw-r--r--crates/rust-analyzer/src/bin/main.rs4
-rw-r--r--xtask/src/install.rs2
-rw-r--r--xtask/src/main.rs12
7 files changed, 94 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b6b6f0341..35713a0c4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -449,6 +449,12 @@ dependencies = [
449] 449]
450 450
451[[package]] 451[[package]]
452name = "fs_extra"
453version = "1.2.0"
454source = "registry+https://github.com/rust-lang/crates.io-index"
455checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
456
457[[package]]
452name = "fsevent" 458name = "fsevent"
453version = "2.0.2" 459version = "2.0.2"
454source = "registry+https://github.com/rust-lang/crates.io-index" 460source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -758,6 +764,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
758checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" 764checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
759 765
760[[package]] 766[[package]]
767name = "jemalloc-ctl"
768version = "0.3.3"
769source = "registry+https://github.com/rust-lang/crates.io-index"
770checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7"
771dependencies = [
772 "jemalloc-sys",
773 "libc",
774 "paste",
775]
776
777[[package]]
778name = "jemalloc-sys"
779version = "0.3.2"
780source = "registry+https://github.com/rust-lang/crates.io-index"
781checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
782dependencies = [
783 "cc",
784 "fs_extra",
785 "libc",
786]
787
788[[package]]
789name = "jemallocator"
790version = "0.3.2"
791source = "registry+https://github.com/rust-lang/crates.io-index"
792checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
793dependencies = [
794 "jemalloc-sys",
795 "libc",
796]
797
798[[package]]
761name = "jod-thread" 799name = "jod-thread"
762version = "0.1.2" 800version = "0.1.2"
763source = "registry+https://github.com/rust-lang/crates.io-index" 801source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1105,6 +1143,25 @@ dependencies = [
1105] 1143]
1106 1144
1107[[package]] 1145[[package]]
1146name = "paste"
1147version = "0.1.18"
1148source = "registry+https://github.com/rust-lang/crates.io-index"
1149checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880"
1150dependencies = [
1151 "paste-impl",
1152 "proc-macro-hack",
1153]
1154
1155[[package]]
1156name = "paste-impl"
1157version = "0.1.18"
1158source = "registry+https://github.com/rust-lang/crates.io-index"
1159checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6"
1160dependencies = [
1161 "proc-macro-hack",
1162]
1163
1164[[package]]
1108name = "paths" 1165name = "paths"
1109version = "0.0.0" 1166version = "0.0.0"
1110 1167
@@ -1165,6 +1222,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1165checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" 1222checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
1166 1223
1167[[package]] 1224[[package]]
1225name = "proc-macro-hack"
1226version = "0.5.19"
1227source = "registry+https://github.com/rust-lang/crates.io-index"
1228checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
1229
1230[[package]]
1168name = "proc-macro2" 1231name = "proc-macro2"
1169version = "1.0.24" 1232version = "1.0.24"
1170source = "registry+https://github.com/rust-lang/crates.io-index" 1233source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1212,6 +1275,7 @@ name = "profile"
1212version = "0.0.0" 1275version = "0.0.0"
1213dependencies = [ 1276dependencies = [
1214 "cfg-if 1.0.0", 1277 "cfg-if 1.0.0",
1278 "jemalloc-ctl",
1215 "la-arena", 1279 "la-arena",
1216 "libc", 1280 "libc",
1217 "once_cell", 1281 "once_cell",
@@ -1354,6 +1418,7 @@ dependencies = [
1354 "ide", 1418 "ide",
1355 "ide_db", 1419 "ide_db",
1356 "itertools 0.10.0", 1420 "itertools 0.10.0",
1421 "jemallocator",
1357 "jod-thread", 1422 "jod-thread",
1358 "log", 1423 "log",
1359 "lsp-server", 1424 "lsp-server",
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml
index 9c7ce26be..f7231c2b8 100644
--- a/crates/profile/Cargo.toml
+++ b/crates/profile/Cargo.toml
@@ -14,12 +14,14 @@ once_cell = "1.3.1"
14cfg-if = "1" 14cfg-if = "1"
15libc = "0.2.73" 15libc = "0.2.73"
16la-arena = { version = "0.2.0", path = "../../lib/arena" } 16la-arena = { version = "0.2.0", path = "../../lib/arena" }
17jemalloc-ctl = { version = "0.3.3", optional = true }
17 18
18[target.'cfg(target_os = "linux")'.dependencies] 19[target.'cfg(target_os = "linux")'.dependencies]
19perf-event = "0.4" 20perf-event = "0.4"
20 21
21[features] 22[features]
22cpu_profiler = [] 23cpu_profiler = []
24jemalloc = ["jemalloc-ctl"]
23 25
24# Uncomment to enable for the whole crate graph 26# Uncomment to enable for the whole crate graph
25# default = [ "cpu_profiler" ] 27# default = [ "cpu_profiler" ]
diff --git a/crates/profile/src/memory_usage.rs b/crates/profile/src/memory_usage.rs
index 83390212a..cb4e54447 100644
--- a/crates/profile/src/memory_usage.rs
+++ b/crates/profile/src/memory_usage.rs
@@ -24,7 +24,12 @@ impl std::ops::Sub for MemoryUsage {
24impl MemoryUsage { 24impl MemoryUsage {
25 pub fn current() -> MemoryUsage { 25 pub fn current() -> MemoryUsage {
26 cfg_if! { 26 cfg_if! {
27 if #[cfg(all(target_os = "linux", target_env = "gnu"))] { 27 if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
28 jemalloc_ctl::epoch::advance().unwrap();
29 MemoryUsage {
30 allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize),
31 }
32 } else if #[cfg(all(target_os = "linux", target_env = "gnu"))] {
28 // Note: This is incredibly slow. 33 // Note: This is incredibly slow.
29 let alloc = unsafe { libc::mallinfo() }.uordblks as isize; 34 let alloc = unsafe { libc::mallinfo() }.uordblks as isize;
30 MemoryUsage { allocated: Bytes(alloc) } 35 MemoryUsage { allocated: Bytes(alloc) }
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index af7b86ead..3cb45b030 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -61,8 +61,14 @@ proc_macro_srv = { path = "../proc_macro_srv", version = "0.0.0" }
61[target.'cfg(windows)'.dependencies] 61[target.'cfg(windows)'.dependencies]
62winapi = "0.3.8" 62winapi = "0.3.8"
63 63
64[target.'cfg(not(target_env = "msvc"))'.dependencies]
65jemallocator = { version = "0.3.2", optional = true }
66
64[dev-dependencies] 67[dev-dependencies]
65expect-test = "1.1" 68expect-test = "1.1"
66test_utils = { path = "../test_utils" } 69test_utils = { path = "../test_utils" }
67mbe = { path = "../mbe" } 70mbe = { path = "../mbe" }
68tt = { path = "../tt" } 71tt = { path = "../tt" }
72
73[features]
74jemalloc = ["jemallocator", "profile/jemalloc"]
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index bf42654a8..2f7f94a39 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -15,6 +15,10 @@ use vfs::AbsPathBuf;
15#[global_allocator] 15#[global_allocator]
16static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; 16static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
17 17
18#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
19#[global_allocator]
20static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
21
18fn main() { 22fn main() {
19 if let Err(err) = try_main() { 23 if let Err(err) = try_main() {
20 eprintln!("{}", err); 24 eprintln!("{}", err);
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index 12962bcfa..202c74426 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -67,6 +67,7 @@ pub struct ServerOpt {
67pub enum Malloc { 67pub enum Malloc {
68 System, 68 System,
69 Mimalloc, 69 Mimalloc,
70 Jemalloc,
70} 71}
71 72
72impl InstallCmd { 73impl InstallCmd {
@@ -176,6 +177,7 @@ fn install_server(opts: ServerOpt) -> Result<()> {
176 let features = match opts.malloc { 177 let features = match opts.malloc {
177 Malloc::System => &[][..], 178 Malloc::System => &[][..],
178 Malloc::Mimalloc => &["--features", "mimalloc"], 179 Malloc::Mimalloc => &["--features", "mimalloc"],
180 Malloc::Jemalloc => &["--features", "jemalloc"],
179 }; 181 };
180 182
181 let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}"); 183 let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}");
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index dec48629c..c3e5c7326 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -49,7 +49,8 @@ FLAGS:
49 --client[=CLIENT] Install only VS Code plugin. 49 --client[=CLIENT] Install only VS Code plugin.
50 CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss' 50 CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'
51 --server Install only the language server 51 --server Install only the language server
52 --mimalloc Use mimalloc for server 52 --mimalloc Use mimalloc allocator for server
53 --jemalloc Use jemalloc allocator for server
53 -h, --help Prints help information 54 -h, --help Prints help information
54 " 55 "
55 ); 56 );
@@ -65,8 +66,13 @@ FLAGS:
65 return Ok(()); 66 return Ok(());
66 } 67 }
67 68
68 let malloc = 69 let malloc = if args.contains("--mimalloc") {
69 if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; 70 Malloc::Mimalloc
71 } else if args.contains("--jemalloc") {
72 Malloc::Jemalloc
73 } else {
74 Malloc::System
75 };
70 76
71 let client_opt = args.opt_value_from_str("--client")?; 77 let client_opt = args.opt_value_from_str("--client")?;
72 78