logoalt Hacker News

Don't use musl if you care about performance

93 pointsby jbellisyesterday at 3:16 PM59 commentsview on HN

Comments

matherialyesterday at 6:20 PM

If your algorithm does a ton of small allocations to the point where the allocator is the bottleneck, you're already doing it wrong. The allocator necessarily comes with a lot of overhead because it needs to accommodate diverse use cases, avoid fragmentation, and ideally, implement a variety of security checks. If you're doing something alloc-intensive, you're probably allocating and freeing a lot of identical structures and you'd be better off grabbing some continuous memory and managing that yourself in a task-specific way.

But the reality is that almost no one actually cares about performance because compute is cheaper than expertise and labor, at least in the short haul. Everything is getting more bloated and slower and we just compensate by adding CPU cores, gigabytes and gigahertz.

show 3 replies
marssaxmanyesterday at 4:27 PM

People have such different perspectives. 26% slower does not sound "terrible" to me; it sounds like quite a reasonable price one might choose to pay for the convenience musl offers. If musl's allocator were 2.6x slower, I might call that "not so great"... but in order to qualify as "terrible" I think the difference would have to be an order of magnitude!

show 7 replies
bloppeyesterday at 4:56 PM

This is only one aspect of "performance". glibc's allocator may be faster, but it also uses more memory.

For a much more technical discussion, see https://github.com/sharkdp/fd/issues/710

lrvickyesterday at 11:47 PM

I really find complaints about the minimum viable placeholder malloc in musl confusing. Does anyone seriously try to use malloc-ng for performance critical use cases?

Our entire linux distro is musl based BUT we swap out the default malloc with mimalloc for high performance because why would you not? Best of both worlds.

https://codeberg.org/stagex/stagex/src/branch/main/packages/...

mattrighettiyesterday at 5:04 PM

Posted this the other day but the whole musl allocator thing seems to be well known [0]

[0]: https://news.ycombinator.com/item?id=45143347

show 1 reply
grep_ityesterday at 4:23 PM

I think the size of linked binaries and simplicity were always the main features?

show 2 replies
tombertyesterday at 7:11 PM

I feel with Rust I try and avoid re-allocations in most cases anyway, so I'm not sure that musl's allocator being slow would significantly affect performance (though I haven't benchmarked it). I feel like part of the appeal of Rust is that you can do imperatively-style mutation-heavy code comparatively risk-free, so despite me normally being the "Functional Programming Nerd", I generally write Rust in a style that's a bit closer to C.

I use musl for my Rust stuff because I have noticed that for the stuff I write it appears to have a lower memory footprint; since a lot of what I do is IO-bound anyway, I care more about using less memory than raw performance.

OptionOfTyesterday at 4:30 PM

Are there other options if I want to ship a 'FROM scratch' image with just a single Rust executable, and everything compiled in?

That to me is the main driver for MUSL.

show 3 replies
superdiskyesterday at 8:25 PM

I swear "bifrost" has to be the most overused name in computing, possibly only behind "yggdrasil." I'm not sure what's so magnetic about those names but I've seen at least 10 different things called that.

delducayesterday at 4:27 PM

Also musl is not a complete runtime

up2isomorphismyesterday at 5:57 PM

Funny thing is that the major reason most people use musl is because glibc make it (artificially) hard to do completely static linking.

dchestyesterday at 6:57 PM

[dead]

legasteniggayesterday at 4:59 PM

[dead]

desdenovayesterday at 4:55 PM

Most of musl's performance issues come from their allocator. Using it with a third party high performance allocator allows you to benefit from static linking with very little performance loss.

show 1 reply