Hacker News new | ask | show | jobs
by civility 2555 days ago
Is anyone aware of a good/fast single threaded allocator for cases where you don't need/want to pay for thread safety?
3 comments

Mutexes in Linux are implemented on top of futex, and on Windows on top of WaitForAddress. Uncontested futex (as well as WaitForAddress) never goes to kernel, pure userspace code and in hot path it is quite fast

https://devblogs.microsoft.com/oldnewthing/20170601-00/?p=96...

If you're single threaded then you'll never have mutex contention so they'll always be fast-path. I'd suggest you actually prove that the memory barriers are actually a problem for you via profiling, since it's somewhat unlikely it is.
> If you're single threaded then you'll never have mutex contention so they'll always be fast-path.

Concurrent algorithms (to which multi-thread capable allocators belong) typically necessitate design and performance compromises which aren't nullified by creating only a single thread.

> I'd suggest you actually prove that the memory barriers are actually a problem for you via profiling, since it's somewhat unlikely it is.

civility's reply to your post is somewhat rude, but they're right. It's rather arrogant to assume that the poster doesn't know what they're doing, without knowing anything about their specific problem. Modern allocators are complex pieces of software, typically with a lot of knobs and dials, and it is entirely plausible that an allocator tuned for single-threaded programs is more performant for a specific use case than a generic multi-thread allocator.

You can get large gains tuning an allocator for a specific use case, yes, but that's very different from tuning it for thread safety. Particularly since most major allocators use a first-level allocator that's thread-local and is therefore not paying any thread-safety tax in the first place.

> It's rather arrogant to assume that the poster doesn't know what they're doing

Given the question they asked I don't believe it was arrogant at all to assume they don't really know what they were doing. Their response seems to justify the push to start from the basics as well.

Nice job - you've succeeded in being just another condescending asshole.
It's true that shallow comments are frustrating, but aggressive ones are worse. If you keep breaking the site guidelines like you did repeatedly in this thread, we're going to have to ban you. Can I persuade you, instead, to review https://news.ycombinator.com/newsguidelines.html and use HN as intended? It sounds like you know a lot, and we want knowledgeable users. It's just that we want not to have a tirefire wreck of a website more—so we have no choice but to put out flamewars.
Dan, go fuck yourself. By letting people get away with snarky condescending tones and banning people who call them out on it, you're encouraging shitty behavior. "Don't be snarky" is right up top in the comments section of the guidelines, but it's easier for you to chastise me because I called the snarky guy an asshole. That's just lazy on your part.

Aggressive comments aren't worse, they're just easier for you to recognize.

> civility's reply to your post is somewhat rude

Not as rude as I wanted to be. I expect answers like that from Stack Overflow or Reddit - just another condescending ego play without actually addressing the question.

Regardless, thank you for your reply.

I don't suppose you know a good single-threaded (or share-nothing across threads) allocator worth looking at?

Your answer is trite and unhelpful.