Baby’s First Garbage Collector (2013)
journal.stuffwithstuff.com
journal.stuffwithstuff.com
Let's say the references are a lot. Like tens of millions order of magnitude.
Would it make sense to GC sweeping it in chunks?
To fix this, you might have the live code that runs in-between the partial mark+sweeps mark objects to be re-swept as it runs. This adds overhead and complexity, of course. This code is apparently called write barriers by Ruby's GC:
https://jemma.dev/blog/gc-incremental
https://blog.peterzhu.ca/notes-on-ruby-gc/
http://www.atdot.net/~ko1/activities/rgengc_ismm.pdf
I'm left wondering what the overhead of such greylisting / write barriers are, compared to the reference counting overhead mentioned by shwestrick in the "Reference count, don't garbage collect" thread:
'write barrier' is a standard term (along with 'read barrier'). See memory management glossary: https://www.memorymanagement.org/glossary/b.html#barrier-1
> wondering what the overhead of such greylisting / write barriers are
https://twitter.com/stevemblackburn/status/14942409060061102...
Read barriers are more expensive.
HOWEVER reads outnumbers writes by a large margin of 10:1 in common code (iirc this was measured in Java code some 20 years ago so might vary by language), so most GC implementations only use write-barriers since they're an prerequisite for incremental GC marking.
Read-barriers are a prerequisite for incremental GC moving if you need to compact the heap (many earlier GC's accept pauses for compacting work since they often compact smaller parts of the heap in each pause), Java ZGC introduced incremental compacting in recent years and whilst it hurts computation performance(called "mutator" in papers) more than just write barriers they were positively surprised at how low they managed to get the penalty.
(Intel put a garbage collector in hardware in the iAPX 432)
So that in 1985?
Why this feature didn't got supported further in today's architectures?
I was in need of a simple garbage collector for a toy project of mine and settled on a copying collector based on Cheney's algorithm at first [1]. The author's mark compact code is so easy to read that I was able to grok it immediately and replace my original GC without trouble and save half my memory.
[0] https://github.com/munificent/lisp2-gc [1] https://en.wikipedia.org/wiki/Cheney%27s_algorithm
Baby’s First Garbage Collector (2013) - https://news.ycombinator.com/item?id=21462190 - Nov 2019 (29 comments)
Baby's First Garbage Collector (2013) - https://news.ycombinator.com/item?id=10794026 - Dec 2015 (17 comments)
Baby's First Garbage Collector - https://news.ycombinator.com/item?id=6871202 - Dec 2013 (84 comments)
A bunch of people much smarter than me all chimed in on how this was a terrible idea. They argued it would destroy the cache and result in worse performance than a traditional garbage collector. Locality matters, apparently. I still sometimes think of this idea but it doesn't fit very well into the actual hardware.
There are concurrency libraries that allocate 8x as much memory as they need just to guarantee that two threads don’t share a cache line.
It is truly a wonderful book, and a much needed (IMHO) addition to the literature. I have a bunch of the classic language books and this is such a good addition, and way easier and more fun to read! If you've been on the fence about ordering, do it!
edit: Like this, https://gist.github.com/Dietr1ch/a636578fe9f06faa5d46e1b78aa...
See also https://stackoverflow.com/questions/12914917/using-pointers-....
I also want to know if Norvig has a biographer, and if not, why not?