3 ms·
> But for short-lived objects, if you have any sort of mark phase, you've already lost. A GC with compactation gives you bump pointer allocation though. No nee
by the8472 11y ago
> But for short-lived objects, if you have any sort of mark phase, you've already lost.
A GC with compactation gives you bump pointer allocation though. No need to traverse free lists. With malloc you potentially have short-lived and long-lived interspersed with each other, creating lots of holes/fragmentation.
> That wouldn't require more than a couple of writes and a TLS lookup.
While you can just null a reference with a single, unfenced write to something that's probably in your L1 cache already. Plus thread-local lists to avoid contention. Complexity grows quickly. It's not exactly free lunch.
- pcwalton 11y ago> A GC with compactation gives you bump pointer allocation though. No need to traverse free lists. With malloc you potentially have short-lived and long-lived interspersed with each other, creating lots of holes/fragmentation. You only get bump pointer allocation in the nursery, not in the tenured generation (unless you want an inefficient tenured generation). In a manually-managed system, short-lived objects usually aren't going to be allocated on the heap at all—they're on the stack. Even for the few that are allocated on the heap, the way free lists work does a great job of keeping them in cache. Fragmentation really isn't much of a problem anymore with modern mallocs like jemalloc and tcmalloc. > While you can just null a reference with a single, unfenced write to something that's probably in your L1 cache already. Plus thread-local lists to avoid contention. I have a hard time believing that the cost of a TLS lookup and a couple of writes per freed object is more expensive than a Cheney scan for objects in the nursery.
- papaf 11y agoI have a hard time believing that the cost of a TLS lookup and a couple of writes per freed object is more expensive than a Cheney scan for objects in the nursery This paper describes how it is possible if you are happy to throw a lot of memory at the problem: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.49.2537&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.49.... Section 3 is titled "Explicit freeing is more expensive".
- pcwalton 11y agoAs with many late 80s memory management papers, cache effects obsolete the conclusions in this one. In fact, the compiler's ability to coalesce all the stack allocations in a single procedure call into a single pair of stack manipulation instructions makes the conclusions almost meaningless in practice: inlining optimizations and modern CPUs make that cost essentially zero nowadays. I'd almost argue that the methodology in this paper, combined with 2015 assumptions, offers an effective argument against GC. Appel's memory management papers really need to be taken with a grain of salt :)
- titzer 11y ago> You only get bump pointer allocation in the nursery, not in the tenured generation (unless you want an inefficient tenured generation). That's not universally true; e.g. V8 can and does allocate pretenured objects in the old generation with bump-pointer allocation.
- pcwalton 11y agoSurely that can't be done in all circumstances without severe memory usage issues or fragmentation problems though. You have to fill those holes eventually, if not during allocation than during compaction.
- titzer 11y agoSure, the GC eventually triggers compaction and that by design will produce a lot of contiguous free memory.