Live data from Hacker News

Why does musl make my Rust code so slow?

andygrove.io

11–20 of 77 posts

Re: Why does musl make my Rust code so slow?

#11
post #4

This actually someone asking and not an investigation and explanation. There isn't even a lot of due diligence to figuring it out - no profiling or resource usage other than CPUs. Also it is musl combined with docker causing a 30x slowdown. If something is running 30x slower from linking in a different libc, I'm guessing it should not be that difficult to narrow down the cause at least a little bit.

Yeah, you should be upvoted.

The author put zero effort into figuring things out.

Re: Why does musl make my Rust code so slow?

#12
post #4

This actually someone asking and not an investigation and explanation. There isn't even a lot of due diligence to figuring it out - no profiling or resource usage other than CPUs. Also it is musl combined with docker causing a 30x slowdown. If something is running 30x slower from linking in a different libc, I'm guessing it should not be that difficult to narrow down the cause at least a little bit.

Yeah, upvoted. 30x slower on 48 core (?) system sounds suspiciously like excessive lock contention (or some other shared resource). Non-NUMA aware allocator (or other code) might also contribute to the issue.

Should be fairly easy to investigate.

Re: Why does musl make my Rust code so slow?

#14
post #7
post #3

Swap out the allocator https://users.rust-lang.org/t/optimizing-rust-binaries-obser...

Without familiarity with rust, I wasn't sure what they meant by "system allocator". Apparently that means libc's malloc. (Or HeapAlloc on Windows) So I guess they statically link jemalloc but can optionally use libc malloc.

It's the other way around now, though the post that iou linked is from an earlier period when things worked differently. By default today, Rust programs use the same allocator that C programs use, which I think is provided by libc on Linux, and you have the option of using a custom allocator, like jemalloc. Historically however, all Rust programs used to use jemalloc by default.

Re: Why does musl make my Rust code so slow?

#15
post #4

This actually someone asking and not an investigation and explanation. There isn't even a lot of due diligence to figuring it out - no profiling or resource usage other than CPUs. Also it is musl combined with docker causing a 30x slowdown. If something is running 30x slower from linking in a different libc, I'm guessing it should not be that difficult to narrow down the cause at least a little bit.

Benchmarking in Docker in general is a mistake I believe.

Re: Why does musl make my Rust code so slow?

#16
post #15
post #4

This actually someone asking and not an investigation and explanation. There isn't even a lot of due diligence to figuring it out - no profiling or resource usage other than CPUs. Also it is musl combined with docker causing a 30x slowdown. If something is running 30x slower from linking in a different libc, I'm guessing it should not be that difficult to narrow down the cause at least a little bit.

Benchmarking in Docker in general is a mistake I believe.

You should probably be measuring your app's performance in a production-like environment though.

Re: Why does musl make my Rust code so slow?

#17
post #5

run a perf trace on both and see what jumps out

You may not even need to go that deep.

Just strace (follow forks) and look what commands get exec'd.

"Why does musl make my Rust code so slow?" But he's measuring mostly the compiler performance in "cargo build". Is he writing the same amount of data to disk in the same experiments? Seems like there's a lot of opportunity for some shallow investigation to find out more.

Re: Why does musl make my Rust code so slow?

#18
post #7

Earlier quoted context omitted.

Without familiarity with rust, I wasn't sure what they meant by "system allocator". Apparently that means libc's malloc. (Or HeapAlloc on Windows) So I guess they statically link jemalloc but can optionally use libc malloc.

It's the other way around now, though the post that iou linked is from an earlier period when things worked differently. By default today, Rust programs use the same allocator that C programs use, which I think is provided by libc on Linux, and you have the option of using a custom allocator, like jemalloc. Historically however, all Rust programs used to use jemalloc by default.

I suppose there's no option to link statically against glibc because of the implications with LGPL (static linking triggers additional license clauses).

Re: Why does musl make my Rust code so slow?

#19
post #18

Earlier quoted context omitted.

It's the other way around now, though the post that iou linked is from an earlier period when things worked differently. By default today, Rust programs use the same allocator that C programs use, which I think is provided by libc on Linux, and you have the option of using a custom allocator, like jemalloc. Historically however, all Rust programs used to use jemalloc by default.

I suppose there's no option to link statically against glibc because of the implications with LGPL (static linking triggers additional license clauses).

I think it's mainly that glibc has poor support for statically linking.

Re: Why does musl make my Rust code so slow?

#20
post #18

Earlier quoted context omitted.

It's the other way around now, though the post that iou linked is from an earlier period when things worked differently. By default today, Rust programs use the same allocator that C programs use, which I think is provided by libc on Linux, and you have the option of using a custom allocator, like jemalloc. Historically however, all Rust programs used to use jemalloc by default.

I suppose there's no option to link statically against glibc because of the implications with LGPL (static linking triggers additional license clauses).

Also, it’s extremely common to leave libc dynamically linked for operational reasons. It’s my understanding that by default Go statically links everything but libc.
Post reply on HN