Skip to content

Published binaries are kinda' slow #3459

Closed
@lnicola

Description

@lnicola
Member

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

Activity

matklad

matklad commented on Mar 4, 2020

@matklad
Member
lnicola

lnicola commented on Mar 4, 2020

@lnicola
MemberAuthor

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

memoryruins commented on Mar 8, 2020

@memoryruins
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

lnicola commented on May 1, 2020

@lnicola
MemberAuthor

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

matklad commented on May 1, 2020

@matklad
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lnicola@matklad@memoryruins

        Issue actions

          Published binaries are kinda' slow · Issue #3459 · rust-lang/rust-analyzer