I'm reading Steve Yegge's "Dynamic Languages Strike Back" talk, and in it he sort of criticizes mark-and-sweep GCs (about 5-10 percent through that link, the "Pigs attempt's to fly" slide) What's wrong with them?
相关问题
- C# GC not freeing memory [duplicate]
- Faster loop: foreach vs some (performance of jsper
- Why wrapping a function into a lambda potentially
- garbage collection best practices
- Ado.net performance:What does SNIReadSync do?
相关文章
- DOM penalty of using html attributes
- Which is faster, pointer access or reference acces
- Django is sooo slow? errno 32 broken pipe? dcramer
- Understanding the difference between Collection.is
- parallelizing matrix multiplication through thread
- How to determine JS bottlenecks in React Native co
- Difference between SuspendLayout and BeginUpdate
- Efficient Rolling Max and Min Window
Here's a high-level bullet point comparison of the various techniques mentioned in the referenced quotation (plus "mark-and-compact" ... which is a variation on mark-and-sweep.)
The properties of reference counting collection are:
For classic mark-and-sweep:
Classical mark-and-sweep is sometimes modified so that the sweep phase compacts the free space by "sliding" non-garbage objects. This is called "mark-sweep-compact". This is fairly complicated but:
Modern collectors (including typical generational collectors) are based on mark-and-copy. The idea is that the collector traces objects in a "from space" copying them to a "to space". When it is done, the "to space" has a contiguous chunk of free space at the end which can be used for allocating new objects. The old "from space" is put on one side for the next time the garbage collector runs. The nice thing about copying collection is that the garbage collection cost associated with a garbage object is close to zero.
A generational collector is one where there are multiple spaces (generations), that are collected at different rates. This is based on the hypothesis that most objects are created and then become unreachable in a short period of time. So by garbage collecting the space containing the young objects, you reclaim a relatively large amount of space at relatively low cost. You still need to collect the older generations, but this can happen less frequently.
(A mark-and-sweep collector could be generational, but the pay-off isn't as great as for a copying collector.)
He's contrasting it to mark-compact:
Plain mark & sweep GCs aren't so good because they have a problem of heap fragmentation. With high allocation levels common of GC-enabled languages, this usually becomes an issue faster than it does in e.g. C++, where a lot of objects just live on the stack.
That said, mark-compact is really mark & sweep with compacting tackled on it, so the terminology could be better. Non-compacting collectors are normally called "conservative" to distinguish them.
Here's the context of the quote:
From the quote, he appears to be talking about fairly primitive GCs which aren't generational. Generational GCs can still be mark and sweep, but they have a lot less to mark most of the time, which makes them a lot faster than "mark and sweep the world every time".
Assuming that's what he meant, I agree - but he could have put it more clearly. Bear in mind that this was a talk rather than a doctoral thesis though - coming up with the clearest possible way of expressing yourself "on the hoof" is kinda tricky :)