Skip to content

Commit 2dd8ba2

Browse files
bors[bot]matklad
andauthored
Merge #5487
5487: Setup global allocator in the correct crate r=matklad a=matklad It worked before, but was roundabout bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 26932e0 + 9ad41eb commit 2dd8ba2

File tree

11 files changed

+13
-119
lines changed

11 files changed

+13
-119
lines changed

Cargo.lock

Lines changed: 1 addition & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_prof/Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,12 @@ doctest = false
1313
ra_arena = { path = "../ra_arena" }
1414
once_cell = "1.3.1"
1515
backtrace = { version = "0.3.44", optional = true }
16-
mimalloc = { version = "0.1.19", default-features = false, optional = true }
1716
cfg-if = "0.1.10"
1817
libc = "0.2.73"
1918

20-
[target.'cfg(not(target_env = "msvc"))'.dependencies]
21-
jemallocator = { version = "0.3.2", optional = true }
22-
jemalloc-ctl = { version = "0.3.3", optional = true }
23-
2419
[features]
25-
jemalloc = [ "jemallocator", "jemalloc-ctl" ]
2620
cpu_profiler = []
2721

2822
# Uncomment to enable for the whole crate graph
2923
# default = [ "backtrace" ]
30-
# default = [ "jemalloc" ]
31-
# default = [ "mimalloc" ]
3224
# default = [ "cpu_profiler" ]

crates/ra_prof/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ pub use crate::{
1313
memory_usage::{Bytes, MemoryUsage},
1414
};
1515

16-
// We use jemalloc mainly to get heap usage statistics, actual performance
17-
// difference is not measures.
18-
#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
19-
#[global_allocator]
20-
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
21-
22-
#[cfg(all(feature = "mimalloc"))]
23-
#[global_allocator]
24-
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
25-
2616
/// Prints backtrace to stderr, useful for debugging.
2717
#[cfg(feature = "backtrace")]
2818
pub fn print_backtrace() {

crates/ra_prof/src/memory_usage.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! FIXME: write short doc here
2+
use std::fmt;
23

34
use cfg_if::cfg_if;
4-
use std::fmt;
55

66
pub struct MemoryUsage {
77
pub allocated: Bytes,
@@ -11,13 +11,7 @@ pub struct MemoryUsage {
1111
impl MemoryUsage {
1212
pub fn current() -> MemoryUsage {
1313
cfg_if! {
14-
if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
15-
jemalloc_ctl::epoch::advance().unwrap();
16-
MemoryUsage {
17-
allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()),
18-
resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()),
19-
}
20-
} else if #[cfg(target_os = "linux")] {
14+
if #[cfg(target_os = "linux")] {
2115
// Note: This is incredibly slow.
2216
let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as usize;
2317
MemoryUsage { allocated: Bytes(alloc), resident: Bytes(0) }

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ serde = { version = "1.0.106", features = ["derive"] }
2929
serde_json = "1.0.48"
3030
threadpool = "1.7.1"
3131
rayon = "1.3.1"
32+
mimalloc = { version = "0.1.19", default-features = false, optional = true }
3233

3334
stdx = { path = "../stdx" }
3435

@@ -62,7 +63,3 @@ expect = { path = "../expect" }
6263
test_utils = { path = "../test_utils" }
6364
mbe = { path = "../ra_mbe", package = "ra_mbe" }
6465
tt = { path = "../ra_tt", package = "ra_tt" }
65-
66-
[features]
67-
jemalloc = [ "ra_prof/jemalloc" ]
68-
mimalloc = [ "ra_prof/mimalloc" ]

crates/rust-analyzer/src/bin/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ USAGE:
166166
FLAGS:
167167
-o, --only Only analyze items matching this path
168168
-h, --help Prints help information
169-
--memory-usage Collect memory usage statistics (requires `--features jemalloc`)
169+
--memory-usage Collect memory usage statistics
170170
--randomize Randomize order in which crates, modules, and items are processed
171171
--parallel Run type inference in parallel
172172
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
@@ -221,7 +221,7 @@ USAGE:
221221
222222
FLAGS:
223223
-h, --help Prints help information
224-
--memory-usage Collect memory usage statistics (requires `--features jemalloc`)
224+
--memory-usage Collect memory usage statistics
225225
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
226226
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
227227
-v, --verbose

crates/rust-analyzer/src/bin/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use vfs::AbsPathBuf;
1616

1717
use crate::args::HelpPrinted;
1818

19+
#[cfg(all(feature = "mimalloc"))]
20+
#[global_allocator]
21+
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
22+
1923
fn main() -> Result<()> {
2024
setup_logging()?;
2125
let args = match args::Args::parse()? {

docs/dev/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,7 @@ To log all communication between the server and the client, there are two choice
397397

398398
There are also two VS Code commands which might be of interest:
399399

400-
* `Rust Analyzer: Status` shows some memory-usage statistics. To take full
401-
advantage of it, you need to compile rust-analyzer with jemalloc support:
402-
```
403-
$ cargo install --path crates/rust-analyzer --force --features jemalloc
404-
```
405-
406-
There's an alias for this: `cargo xtask install --server --jemalloc`.
400+
* `Rust Analyzer: Status` shows some memory-usage statistics.
407401

408402
* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection.
409403

xtask/src/dist.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ fn dist_server() -> Result<()> {
5757
env::set_var("CC", "clang");
5858
run!(
5959
"cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release"
60-
// We'd want to add, but that requires setting the right linker somehow
61-
// --features=jemalloc
6260
)?;
6361
} else {
6462
run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?;

xtask/src/install.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub struct ServerOpt {
2424

2525
pub enum Malloc {
2626
System,
27-
Jemalloc,
2827
Mimalloc,
2928
}
3029

@@ -138,7 +137,6 @@ fn install_server(opts: ServerOpt) -> Result<()> {
138137

139138
let malloc_feature = match opts.malloc {
140139
Malloc::System => "",
141-
Malloc::Jemalloc => "--features jemalloc",
142140
Malloc::Mimalloc => "--features mimalloc",
143141
};
144142
let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", malloc_feature);

0 commit comments

Comments
 (0)