diff options
-rw-r--r-- | Cargo.lock | 65 | ||||
-rw-r--r-- | crates/profile/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/profile/src/memory_usage.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 4 | ||||
-rw-r--r-- | xtask/src/install.rs | 2 | ||||
-rw-r--r-- | xtask/src/main.rs | 12 |
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]] |
452 | name = "fs_extra" | ||
453 | version = "1.2.0" | ||
454 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
455 | checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" | ||
456 | |||
457 | [[package]] | ||
452 | name = "fsevent" | 458 | name = "fsevent" |
453 | version = "2.0.2" | 459 | version = "2.0.2" |
454 | source = "registry+https://github.com/rust-lang/crates.io-index" | 460 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -758,6 +764,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
758 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" | 764 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" |
759 | 765 | ||
760 | [[package]] | 766 | [[package]] |
767 | name = "jemalloc-ctl" | ||
768 | version = "0.3.3" | ||
769 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
770 | checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" | ||
771 | dependencies = [ | ||
772 | "jemalloc-sys", | ||
773 | "libc", | ||
774 | "paste", | ||
775 | ] | ||
776 | |||
777 | [[package]] | ||
778 | name = "jemalloc-sys" | ||
779 | version = "0.3.2" | ||
780 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
781 | checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" | ||
782 | dependencies = [ | ||
783 | "cc", | ||
784 | "fs_extra", | ||
785 | "libc", | ||
786 | ] | ||
787 | |||
788 | [[package]] | ||
789 | name = "jemallocator" | ||
790 | version = "0.3.2" | ||
791 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
792 | checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" | ||
793 | dependencies = [ | ||
794 | "jemalloc-sys", | ||
795 | "libc", | ||
796 | ] | ||
797 | |||
798 | [[package]] | ||
761 | name = "jod-thread" | 799 | name = "jod-thread" |
762 | version = "0.1.2" | 800 | version = "0.1.2" |
763 | source = "registry+https://github.com/rust-lang/crates.io-index" | 801 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1105,6 +1143,25 @@ dependencies = [ | |||
1105 | ] | 1143 | ] |
1106 | 1144 | ||
1107 | [[package]] | 1145 | [[package]] |
1146 | name = "paste" | ||
1147 | version = "0.1.18" | ||
1148 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1149 | checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" | ||
1150 | dependencies = [ | ||
1151 | "paste-impl", | ||
1152 | "proc-macro-hack", | ||
1153 | ] | ||
1154 | |||
1155 | [[package]] | ||
1156 | name = "paste-impl" | ||
1157 | version = "0.1.18" | ||
1158 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1159 | checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" | ||
1160 | dependencies = [ | ||
1161 | "proc-macro-hack", | ||
1162 | ] | ||
1163 | |||
1164 | [[package]] | ||
1108 | name = "paths" | 1165 | name = "paths" |
1109 | version = "0.0.0" | 1166 | version = "0.0.0" |
1110 | 1167 | ||
@@ -1165,6 +1222,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1165 | checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" | 1222 | checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" |
1166 | 1223 | ||
1167 | [[package]] | 1224 | [[package]] |
1225 | name = "proc-macro-hack" | ||
1226 | version = "0.5.19" | ||
1227 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1228 | checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" | ||
1229 | |||
1230 | [[package]] | ||
1168 | name = "proc-macro2" | 1231 | name = "proc-macro2" |
1169 | version = "1.0.24" | 1232 | version = "1.0.24" |
1170 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1233 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1212,6 +1275,7 @@ name = "profile" | |||
1212 | version = "0.0.0" | 1275 | version = "0.0.0" |
1213 | dependencies = [ | 1276 | dependencies = [ |
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" | |||
14 | cfg-if = "1" | 14 | cfg-if = "1" |
15 | libc = "0.2.73" | 15 | libc = "0.2.73" |
16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } | 16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } |
17 | jemalloc-ctl = { version = "0.3.3", optional = true } | ||
17 | 18 | ||
18 | [target.'cfg(target_os = "linux")'.dependencies] | 19 | [target.'cfg(target_os = "linux")'.dependencies] |
19 | perf-event = "0.4" | 20 | perf-event = "0.4" |
20 | 21 | ||
21 | [features] | 22 | [features] |
22 | cpu_profiler = [] | 23 | cpu_profiler = [] |
24 | jemalloc = ["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 { | |||
24 | impl MemoryUsage { | 24 | impl 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] |
62 | winapi = "0.3.8" | 62 | winapi = "0.3.8" |
63 | 63 | ||
64 | [target.'cfg(not(target_env = "msvc"))'.dependencies] | ||
65 | jemallocator = { version = "0.3.2", optional = true } | ||
66 | |||
64 | [dev-dependencies] | 67 | [dev-dependencies] |
65 | expect-test = "1.1" | 68 | expect-test = "1.1" |
66 | test_utils = { path = "../test_utils" } | 69 | test_utils = { path = "../test_utils" } |
67 | mbe = { path = "../mbe" } | 70 | mbe = { path = "../mbe" } |
68 | tt = { path = "../tt" } | 71 | tt = { path = "../tt" } |
72 | |||
73 | [features] | ||
74 | jemalloc = ["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] |
16 | static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; | 16 | static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; |
17 | 17 | ||
18 | #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] | ||
19 | #[global_allocator] | ||
20 | static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
21 | |||
18 | fn main() { | 22 | fn 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 { | |||
67 | pub enum Malloc { | 67 | pub enum Malloc { |
68 | System, | 68 | System, |
69 | Mimalloc, | 69 | Mimalloc, |
70 | Jemalloc, | ||
70 | } | 71 | } |
71 | 72 | ||
72 | impl InstallCmd { | 73 | impl 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 | ||