Live data from Hacker News

High-performance garbage collection for C++

v8.dev

21–25 of 25 posts

Re: High-performance garbage collection for C++

#21
post #9

It's a non-moving collector. It might be high performance by the standards of C++ garbage collectors, but I doubt its performance could be anywhere near what a decent JVM can manage, especially in the absence of finalizers/destructors. As Ron Pressler ( pron here on HN) has been emphasising recently, [0] the 'sweep' phase of a moving garbage collector is unaffected by the size or number of dead objects in the heap (a…

I think it's a good thing to separate requirements/problems/etc. 1: Java has an horrendeous amount of unnecessary garbage due to their erasing generic design (until Valhalla ever arrives), there was some old blog post that chronicled the creation of Dictionary for C#'s System.Collections.Generic (as opposed to the initial Java-like System.Collections) and how it reduced garbage-load by an magnitude. Java chose compat…

On your third point (compilers and Boehm): agreed on both counts. The C++11 "garbage collection support" (declare_reachable and friends) never got an implementation and C++23 removed it, so a collector for C++ has to live without the compiler - and Boehm, being conservative on the heap and stop-the-world, is what most people think that has to mean.

It doesn't. I've been building one as a plain header-only library (SGCL, https://github.com/pebal/sgcl - my project): the heap is traced precisely through per-type pointer maps the collector builds at runtime by elimination (a word ever seen holding a non-heap value is data, for good), marking and sweeping run concurrently with the mutators and in parallel over helper threads, cycles are generational, and nothing is ever moved. What it can't do without the compiler is the stacks, which it scans conservatively, like Go before 1.4.

On the "abstract model" point: you're right that it isn't 100% faithful either. The collector reads words of objects while other threads write them, relies on word-sized stores being what every real platform makes them, and reads stacks it does not own. The rules the program has to keep are few (a tracked pointer lives on a stack or in a managed object, never shares storage with data, destructors don't touch peers) and debug builds check them, but it is engineering on top of the platforms, not the standard.

Re: High-performance garbage collection for C++

#22
post #8

It's interesting reading this, wondering how much C++26 static reflection could improve the ergonomics of a system like this. Like, if you tag the class with a specific attribute, can you have have it generate the Trace() function automatically? Can you have it automatically wrap the other GC classes using the Member template? I think implementing the Trace() function might be doable (you'd do it in the GarbageCollec…

Automatic trace definetly yes, however since they also removed GC support from the standard it's quite useless (exact object tracing is useless if you cannot accurately scan the stack). Also co-routines with it's under the hood management of coroutine stack probably would've complicated GC support even more...

The standard provided no GC support. What was there was completely useless.

Re: High-performance garbage collection for C++

#23
post #17

Earlier quoted context omitted.

Automatic trace definetly yes, however since they also removed GC support from the standard it's quite useless (exact object tracing is useless if you cannot accurately scan the stack). Also co-routines with it's under the hood management of coroutine stack probably would've complicated GC support even more...

C++11 GC was useless from the start, I don't get how it ended up being voted in. At the time the two main customers of having a C++ GC would be Unreal C++ and C++/CLI, the design that landed on the standard serves neither of them, thus no one adopted it.

Peeked a bit more at the C++ 11 stuff, it seems very Boehm specific and yes quite uesless (I doubt the C++/CLI people ever considered the stuff in the standard).

Having written a bunch of more or less complete GC based runtimes, the boundary between C++ code and runtime code is often painful mostly due to GC tracking and reading the article I can only concur with what they're doing with Oilpan for V8/Chrome.

Having had a way in C++ to interrogate the current stack and then trace objects (via C++26 reflections) would've sufficed and probably alleviated the need for a separate GC.

Re: High-performance garbage collection for C++

#24
post #22

Earlier quoted context omitted.

Automatic trace definetly yes, however since they also removed GC support from the standard it's quite useless (exact object tracing is useless if you cannot accurately scan the stack). Also co-routines with it's under the hood management of coroutine stack probably would've complicated GC support even more...

The standard provided no GC support. What was there was completely useless.

It seemed very Boehm specific and yes quite uesless.

Wrote a bit more in the sibling comment to pjmpl.

Re: High-performance garbage collection for C++

#25
post #17

Earlier quoted context omitted.

C++11 GC was useless from the start, I don't get how it ended up being voted in. At the time the two main customers of having a C++ GC would be Unreal C++ and C++/CLI, the design that landed on the standard serves neither of them, thus no one adopted it.

Peeked a bit more at the C++ 11 stuff, it seems very Boehm specific and yes quite uesless (I doubt the C++/CLI people ever considered the stuff in the standard). Having written a bunch of more or less complete GC based runtimes, the boundary between C++ code and runtime code is often painful mostly due to GC tracking and reading the article I can only concur with what they're doing with Oilpan for V8/Chrome. Having h…

Yes indeed, and that is why it got removed from the standard eventually, however the question remains how was this even voted in.

Which is why I became kind of vocal regarding existing practice, or at least preview for community feedback, as there are already several examples of stuff landing into the standard that were not properly baked to start with.

Post reply on HN