TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why does musl make my Rust code so slow?

154 pointsby andygroveabout 5 years ago

9 comments

iouabout 5 years ago
Swap out the allocator <a href="https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;optimizing-rust-binaries-observation-of-musl-versus-glibc-and-jemalloc-versus-system-alloc&#x2F;8499" rel="nofollow">https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;optimizing-rust-binaries-obser...</a>
评论 #23081059 未加载
评论 #23080555 未加载
jessermeyerabout 5 years ago
For those curious, Musl&#x27;s malloc implementation is currently being re-written for higher performance and robustness, see <a href="https:&#x2F;&#x2F;github.com&#x2F;richfelker&#x2F;mallocng-draft" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;richfelker&#x2F;mallocng-draft</a>
评论 #23083775 未加载
评论 #23082261 未加载
daliasabout 5 years ago
We&#x27;d be happy to address specific problems on the mailing list. I believe it&#x27;s a known issue that the Rust compiler is making really heavy use of rapid allocation&#x2F;freeing cycles, and would benefit from linking a performance-oriented malloc replacement. Doing so is inherently a tradeoff between many factors including performance, memory overhead, safety against erroneous usage by programs, etc.<p>One statement in your post, which some readers pointed out was apparently added later, &quot;Others have suggested that the performance problems in musl go deeper than that and that there are fundamental issues with threading in musl, potentially making it unsuitable for my use case,&quot; seems wrong unless they just meant that the malloc implementation is not thread-caching&#x2F;thread-local-arena-based. The threads implementation in musl is the only one I&#x27;m aware of that doesn&#x27;t still have significant bugs in some of the synchronization primitives or in cancellation. It&#x27;s missing a few optional and somewhat obscure features like priority-ceiling mutexes, and Linux doesn&#x27;t even admit a fully correct implementation in some regards like interaction of thread priorities with some synchronization primitives, but all the basic functionality is there and was written with extreme attention to correctness, and musl aims to be a very good choice in situations where this matters.
underdeserverabout 5 years ago
...Not the Intel guy, if anyone else had to pause for a second.
评论 #23080976 未加载
pedrocrabout 5 years ago
Swapping out the allocator for jemalloc would be my first try. It&#x27;s easy to do and often results in better performance. 30x requires some kind of pathological case though.
评论 #23080651 未加载
pjc50about 5 years ago
.. where&#x27;s the profile output?
termieabout 5 years ago
run a perf trace on both and see what jumps out
评论 #23080897 未加载
评论 #23080812 未加载
renewiltordabout 5 years ago
Post was not very illuminating. Very little content. It&#x27;s pretty much a &quot;if musl is slow, it may be the allocator (eom)&quot; which fits in the headline and would have saved me the click.
BubRossabout 5 years ago
This actually someone asking and not an investigation and explanation. There isn&#x27;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.<p>If something is running 30x slower from linking in a different libc, I&#x27;m guessing it should not be that difficult to narrow down the cause at least a little bit.
评论 #23080745 未加载
评论 #23081415 未加载
评论 #23080744 未加载
评论 #23080834 未加载