← Back to context

Comment by aw1621107

2 hours ago

> If we only traced young objects

Careful; just because you only collect in the new generation doesn't mean that you only trace the new generation. From my understanding a rudimentary generational GC design is to include the old generation in the GC roots so you don't need to examine everything in the new generation - if it's not reachable from the roots it's implicitly dead, and the latter category is assumed to apply to most objects in the new generation under the generational hypothesis.

> just because you only collect in the new generation doesn't mean that you only trace the new generation.

Well, then I suppose you're saying the up-thread comment is wrong?

TFA:

> Every one of those pointers has to be followed on every cycle

The comment:

> That's a strange thing to assert, having acknowledged the existence of generational GC.

Which would imply that's not the case, i.e., that we're not considering every pointer in every GC sweep. (Which, again, I thought was largely the point of generational GCs: to make sweeps cheap by not considering every pointer.)

I guess if it's really the sweep that's the expensive part, then perhaps doing a full walk is fine.

> generational GC design is to include the old generation in the GC roots so you don't need to examine everything in the new generation

I'm assuming roots (stack references to objects) are separate from generations (which heap objects belong to).

I suppose if you added old objects to the set of roots, that'd also solve it, but that's the same as "every one of those pointers has to be followed on every cycle".

The sibling post thinks writes are made more expensive by tainting/young-ifying objects that get written to. In that way, we prevent an old object from ever pointing at a new one — at the cost of writes now being more than a write.

Edit: Yeah, here's [a note](https://chromium.googlesource.com/v8/v8/+/refs/heads/13.3.25...) about how Chrome implements it. There is additional book-keeping and cost to writes.