This probably wouldn’t work but I can’t figure out why…
Garbage collectors can either stop the world, which has the most throughput, but ruins real-time performance, or it could be concurrent, and there are many versions of that. However, they might rely on locking, write barriers, etc, which can slow down processing. This is needed to prevent all sorts of shenanigans of temporarily unreachable objects, race conditions, etc.
This was really disappointing to me. This could be a major problem in the Julia language. So, I decided to ponder up some ideas, and not knowing much about GC, this idea is probably stupid, but hey, I need to give this idea a try.
I propose a high-throughput, concurrent garbage collector based on mark-and-sweep. The first mechanism is probabilistic mark and sweep. Unlike traditional mark and sweep which relies on stopping the world, locking, or other synchronization to ensure the reference graph doesn’t change, the first preliminary round operates on an N-mark system. The system runs the marking process several times. Only objects seen as unreachable N times in a row get declared dead. Then, before the actual sweep, you enter a low-overhead period where each deletion of a pointer must be accompanied by adding the referenced object to be marked as well. During this time, the GC thread performs a final mark. If the GC found anything not marked or the pointer deletion found anything unmarked, then the GC aborts the process, and the probabilistic GC begins again.
This does need to assume a few things; for example, that the race condition only invalidates the written value but does not cause further undefined behaviors. This also would need a lot of probabilistic reasoning and so on. Also, programming while tolerating race conditions can be nightmarishly difficult. Finally, the idea probably wouldn’t work or need a lot of refinement due to some unknown reasons, but I want to put it out anyway.
Maybe those of you knowing more about GC will know why it wouldn’t work, but on the off chance that it could work, well, I’m happy to contribute something even if it’s just an idea.