3 ms·
Let me preface by stating that I'm no expert. I created the repo a few years ago when I was self-studying gc. Then I realized the rabbit hole was much deeper th
by bjourne 4y ago
Let me preface by stating that I'm no expert. I created the repo a few
years ago when I was self-studying gc. Then I realized the rabbit hole
was much deeper than I thought and retreated. The book I read is The
Garbage Collection Handbook. Quite expensive but definitely worth its
price.
Throughput-wise, it's hard to beat naive tracing gc. The algorithms
are just too simple and they don't "interfere" with "normal
operations" like ref counting does. Assuming the same allocation
pattern (i.e no cheating by stack allocating objects), a tracing gc
would likely (again, throughput-wise) beat manual memory management
too. The additional benefit tracing gives you is easy heap
compaction. Thus future pointer-chasing and memory allocations will be
more efficient. With ref counting, compaction is harder.
True, you could delay sweeping, but ime, marking time dominates so you
don't gain much. Even with a huge heap of several gigabytes, sweeping is
just a linear scan from lowest to highest address.
Quick fit is a memory allocator, see:
http://www.flounder.com/memory_allocation.htm http://www.flounder.com/memory_allocation.htm Most gcs do not keep the
heap contiguous so you need it in a layer below the gc. Quick fit is
the algorithm almost everyone uses and it is very good for allocating
many small objects of fixed sizes (8, 16, 32, etc.). It could be
swapped out with malloc/free pairs instead, at the price of some
performance.
I have to disgree with naive tracing being advanced. My mark & sweep
implementation is only about 50 lines and that includes comments:
https://github.com/bjourne/c-examples/blob/master/libraries/collectors/mark-sweep.c#L33 https://github.com/bjourne/c-examples/blob/master/libraries/...
A copying collector isn't much more complicated. Neither is beyond the
reach of most comp sci students. Yes, optimized multi-generational
tracing collectors supporting concurrent and resumable tracing makes
them very complicated. But the same is true of optimized ref counting
schemes. :)
Pony looks very interesting. It looks like it is supposed to have less
object churn than very dynamic languages like JavaScript which
probably makes ref counting very suitable for it.