Skip to content

Published binaries are kinda' slow #3459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lnicola opened this issue Mar 4, 2020 · 5 comments
Closed

Published binaries are kinda' slow #3459

lnicola opened this issue Mar 4, 2020 · 5 comments

Comments

@lnicola
Copy link
Member

lnicola commented Mar 4, 2020

The musl allocator is not one of the fastest ones out there. We should consider enabling jemalloc if possible.

$ target/release/rust-analyzer analysis-stats .                                                                                               Database loaded, 185 roots, 207.149744ms
Crates in this dir: 27
Total modules found: 391
Total declarations: 6479
Total functions: 4882
Item Collection: 12.928391044s, 0b allocated 0b resident
Total expressions: 134876                                                                                                               
Expressions of unknown type: 4420 (3%)
Expressions of partially unknown type: 4193 (3%)
Type mismatches: 271
Inference: 38.903396336s, 0b allocated 0b resident
Total: 51.83179408s, 0b allocated 0b resident

$ target/x86_64-unknown-linux-musl/release/rust-analyzer analysis-stats .                                                                                      Database loaded, 185 roots, 236.729051ms
Crates in this dir: 27
Total modules found: 391
Total declarations: 6479
Total functions: 4882
Item Collection: 14.239506998s, 0b allocated 0b resident
Total expressions: 134876                                                                                                               
Expressions of unknown type: 4438 (3%)
Expressions of partially unknown type: 4284 (3%)
Type mismatches: 271
Inference: 44.227304328s, 0b allocated 0b resident
Total: 58.466818431s, 0b allocated 0b resident
@matklad
Copy link
Member

matklad commented Mar 4, 2020 via email

@lnicola
Copy link
Member Author

lnicola commented Mar 4, 2020

It does, with a bit of prodding. I had to set my linker to musl-clang (remember that ~/.cargo/config tweak?). Looks like musl-jemalloc is on par with glibc.

$ target/release/rust-analyzer analysis-stats .                                                                                               Database loaded, 185 roots, 207.976195ms
Crates in this dir: 27
Total modules found: 391
Total declarations: 6479
Total functions: 4882
Item Collection: 12.205624894s, 534mb allocated 563mb resident
Total expressions: 134876                                                                                                               
Expressions of unknown type: 4429 (3%)
Expressions of partially unknown type: 4281 (3%)
Type mismatches: 271
Inference: 35.106950861s, 2107mb allocated 2185mb resident
Total: 47.312756967s, 2107mb allocated 2185mb resident

$ target/x86_64-unknown-linux-musl/release/rust-analyzer analysis-stats .                                                                                      Database loaded, 185 roots, 242.025021ms
Crates in this dir: 27
Total modules found: 391
Total declarations: 6479
Total functions: 4882
Item Collection: 13.722411216s, 534mb allocated 570mb resident
Total expressions: 134876                                                                                                               
Expressions of unknown type: 4448 (3%)
Expressions of partially unknown type: 4282 (3%)
Type mismatches: 271
Inference: 37.752254669s, 2104mb allocated 2183mb resident
Total: 51.474874324s, 2104mb allocated 2183mb resident

@memoryruins
Copy link
Contributor

Noticed that ripgrep also enables jemalloc for 64-bit musl https://github.com/BurntSushi/ripgrep/blob/0874aa115c92f102a6ec474944f589667463fcd0/crates/core/main.rs#L29-L44

// However, when ripgrep is built with musl, this means ripgrep will use musl's
// allocator, which appears to be substantially worse. (musl's goal is not to
// have the fastest version of everything. Its goal is to be small and amenable
// to static compilation.) Even though ripgrep isn't particularly allocation
// heavy, musl's allocator appears to slow down ripgrep quite a bit. Therefore,
// when building with musl, we use jemalloc.
//
// We don't unconditionally use jemalloc because it can be nice to use the
// system's default allocator by default. Moreover, jemalloc seems to increase
// compilation times by a bit.
//
// Moreover, we only do this on 64-bit systems since jemalloc doesn't support
// i686.
#[cfg(all(target_env = "musl", target_pointer_width = "64"))]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

@lnicola
Copy link
Member Author

lnicola commented May 1, 2020

Update: in #4157 we've switched to glibc binaries, so this is partly fixed, assuming it sticks. There's still the option of enabling jemalloc.

@matklad
Copy link
Member

matklad commented May 1, 2020

Yeah, I think we should maybe close this for now -- if the goal is better perf, the bigger impact would be in optimizing stuff inside rust-analyzer itself.

@matklad matklad closed this as completed May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants