-
Notifications
You must be signed in to change notification settings - Fork 13.4k
#[global_allocator] in dependent crate can be optimized away #64402
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
It looks like |
I think that |
@jorendorff to confirm you added |
First question, yes. Second question, no. Instead, I made a separate project to play with, and in that project |
AFAIK |
Here's the repo that shows the bug: https://github.com/jorendorff/rust-lang-bug-64402/ The allocator in this repo panics on Adding |
|
Ok, thanks for the clarification! In that case, yes, Most crates when linked don't actually have any side effect (e.g. just a bland rlib), but some crates (like the global allocator) when linked actually affect how the compiler structures things. To be conservative the As a bug the compiler could perhaps give special treatment to |
Is this also a bug that, e.g., |
@jorendorff this is what I mean by topmost crate: https://gist.github.com/mati865/05f96512240e974dec0ca9740316bde6 the same thing should apply for |
@gnzlbg I don't really know for sure, I'd try it out. If that works then |
Fixes rust-lang#64731, rust-lang#73531. See also rust-lang#64402#issuecomment-530852886
Clarify --extern documentation. Fixes rust-lang#64731, rust-lang#73531. See also rust-lang#64402 (comment)
The uv-performance-memory-allocator is currently optimized out at least on musl due to the crate being otherwise unused (rust-lang/rust#64402), causing musl to not use jemalloc and being slow. Command: ``` cargo build --target x86_64-unknown-linux-musl --profile profiling hyperfine --warmup 1 --runs 10 --prepare "uv venv -p 3.12" "target/x86_64-unknown-linux-musl/profiling/uv pip compile scripts/requirements/airflow.in" ``` Before: ``` Time (mean ± σ): 1.149 s ± 0.013 s [User: 1.498 s, System: 0.433 s] Range (min … max): 1.131 s … 1.173 s 10 runs ``` After: ``` Time (mean ± σ): 552.6 ms ± 4.7 ms [User: 771.7 ms, System: 197.5 ms] Range (min … max): 546.4 ms … 561.6 ms 10 runs ```
The uv-performance-memory-allocator is currently optimized out at least on musl due to the crate being otherwise unused (rust-lang/rust#64402), causing musl to not use jemalloc and being slow. Command: ``` cargo build --target x86_64-unknown-linux-musl --profile profiling hyperfine --warmup 1 --runs 10 --prepare "uv venv -p 3.12" "target/x86_64-unknown-linux-musl/profiling/uv pip compile scripts/requirements/airflow.in" ``` Before: ``` Time (mean ± σ): 1.149 s ± 0.013 s [User: 1.498 s, System: 0.433 s] Range (min … max): 1.131 s … 1.173 s 10 runs ``` After: ``` Time (mean ± σ): 552.6 ms ± 4.7 ms [User: 771.7 ms, System: 197.5 ms] Range (min … max): 546.4 ms … 561.6 ms 10 runs
jemallocator-global
is a library intended to make jemalloc your allocator. It works by declaring a static allocator with#[global_allocator]
.However, a downstream crate linked with
jemallocator-global
nonetheless uses the system malloc on MacOS X.After experimenting a bit with
#[global_allocator]
, it's behaving as though rustc optimizes away a whole crate if you don't seem to be using it; and it doesn't detect that the global allocator is always used.The text was updated successfully, but these errors were encountered: