Re:Why does musl make my Rust code so slow? (2020)
by the_mitsuhiko on Tuesday December 12, 2023 @04:26PM
(#38618810)
> Hmm... if the allocator affects performance so much, then maybe the code simply uses the allocator too frequently?
I'm not familiar with musl's allocator so it's hard for me to say anything about it. However what is pretty common is that modern allocators use thread local allocators to avoid hammering global locks too much. Since Rust is very concurrent you don't need too many allocations to benefit from these optimizations.
Re:Why does musl make my Rust code so slow? (2020)
by a_humean on Tuesday December 12, 2023 @02:45PM
(#38617336)
Not sure its right to blame the code when changing the base image/allocator results in 30x performance improvements on the same hardware. I would be inclined to blame a poor choice of base image/allocator.
Re:Why does musl make my Rust code so slow? (2020)
by croemer on Tuesday December 12, 2023 @02:49PM
(#38617422)
It's not a docker thing, we're getting the same 30x performance hit without using docker, simply compiling musl vs glibc binaries with the default allocator chosen by Rust.
Re:Why does musl make my Rust code so slow? (2020)
by croemer on Tuesday December 12, 2023 @02:48PM
(#38617379)
Every optimization that you don't need to do is a win. With glibc, performance impact of unnecessary allocations might be minimal, but with musl allocations suddenly matter a lot.
Re:Why does musl make my Rust code so slow? (2020)
by wredue on Tuesday December 12, 2023 @05:37PM
(#38619704)
In a lot of ways, rust definitely encourages heavy use of allocator.
Even if you program better for it, one of the prevailing opinions on “learning about lifetimes” is to “not learn lifetimes, just make copies”.
Re:Why does musl make my Rust code so slow? (2020)
by hayley-patton on Tuesday December 12, 2023 @06:22PM
(#38620242)
If the allocator can't keep up with the code, then maybe the allocator simply is bad?
Re:Why does musl make my Rust code so slow? (2020)
by lmm on Tuesday December 12, 2023 @11:20PM
(#38622597)
> putting each C++ object into its own heap allocation behind a smart pointer, creating and destroying tiny objects all the time
Are C++ allocators so bad that they can't handle this use pattern? Yes, you can make a bunch of manual effort to use the allocator less, but you shouldn't have to.
In C++, if someone starts frantically searching for a faster general purpose allocator then it's usually a sign of putting each C++ object into its own heap allocation behind a smart pointer, creating and destroying tiny objects all the time, and then wondering why so much time is spent in the allocator.