I think the reason why C/C++ malloc is at least an order of magnitude slower than that is that those programs don’t allocate as much as programs in GC’d languages do, so compilers/libraries don’t see the need to optimize to that level. It’s nothing inherent about heap allocation.
-
-
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
-
I think the problem is not the speed of the average case is but the nondeterminism it introduces. So you wouldn't want to do heap allocation in a real time (soft or hard) context. I'd go a bit further to say that a web server request should be treated as soft-real-time
- 4 more replies
New conversation -
-
-
this is entirely the fault of approximately every libc having an extremely bad malloc implementation
-
(i was recently shown a very cool flamegraph that spent >60% of its time in either `malloc` or `free`)
- 6 more replies
New conversation -
-
-
Allocation isn't the problem. De-allocation and caches are
-
Zero filling is also the problem Bad locality in data structures is also the problem Too many pointers to follow and space used by headers in pure-OO is also the problem Pinning/copying for native calls is also the problem Safepoints and barriers are also the problem...
End of conversation
New conversation -
-
-
I sometimes even wish it was not that fast in JVMs. If allocation was orders of magnitude slower, GC would not have to run that often! /me comes out with putting sleep(1) after every MB allocated.
-
Also, at least Java allocations mostly bottleneck on zeroing/initializing the storage. If you have sbrk()-like alloc, you can literally allocate terabytes/sec on conventional machines. If you manage to bypass storage initialization on Java, then:pic.twitter.com/rroeCGAVHn
- 1 more reply
New conversation -
-
-
When I write systems I don't think of a generic "heap", but of buffers/allocators that acquire and manage memory in different ways for specific purposes. Heap allocation is a generic term, doesn't tell me much, unless you are heap allocating iterators like Java which is just bad
-
Yeah, this is the right way to think about it IMO. Back in the early days of Lisp and such they often didn’t have the stark division into stack and heap, which C largely popularized
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.