4 ms·
> The idea that just because “who is pointing to this object” is a hard question we are not going to even try to track it, and instead repeatedly scan large par
by dragontamer 5y ago
> The idea that just because “who is pointing to this object” is a hard question we are not going to even try to track it, and instead repeatedly scan large parts of the heap to recover that information later, really makes me cringe.
Its cringy, but the more you think about it, the better it gets.
Only "Live Memory" costs you time in the scan. If there's a long-lived object, you move the long-lived objects to the "old generation" and now its not costing you any scan-time anymore.
As such, the "cost" of memory collection is in fact O(n), where n is the amount of effective live-memory. And its somewhat easy to keep "n" small in many cases.
Its one of those things that you think "Oh, that can't possibly be efficient", but then any alternative (ex: ref-counts) end up also being O(n) operations or worse (every single shared_ptr in C++ needs to be ref_count++ and ref_count-- repeatedly as you copy the values onto the stack... and those ref_count++ need to be cohesive across threads. The ref_count-- needs to be sequentially-consistent and 100% sure that its time to cleanup when that ref_count does in fact reach 0)
Once you think of adding all of those thread-synchronization primitives onto the shared ref_count variable to guarantee smooth operation of ref_count-- (which happens to be 0)... all of a sudden Java's generational collector leads to better multithreaded performance in some scenarios.
----------
> Ownership Analysis
Well, that's a nifty idea to say the least. To use static compile-time analysis to reduce the costly ref_count++ and ref_count-- operations (again: costly because they need to be globally synchronized). So it sounds like the general gist is to optimize away most of those ref_count++ and ref_count-- operations as possible, through some kind of compile-time magic.
EDIT: I guess its not magic since this "Lobster" is a new programming language. So that analysis is in fact the point of this discussion! I have my doubts that this analysis will prove to be useful in highly dynamic situations (ex: Lisp lists, which are linked-lists on steroids). But maybe that's not a problem. If "most code" leads to the straightforward simple scenario, then you get the benefits of the analysis in "most situations".
I don't think that most code use dynamic memory. Its just difficult for most programmers to think of.
- delusional 5y agoIf your ok with stopping the world every once in a while I don't think recounting needs to be globally synchronized. You just stop the world, do the recount from an append only thread safe log, and start the world again. No synchronization needed. What you (arguably) save is a scan of all pointers to see if they point to your object.
- dunham 5y agoIf anyone is interested in more details on the Generational GC in Java, I found an article a few days ago that explains how it works. In particular, it explains how they deal with changes to old gen. https://shipilev.net/jvm/anatomy-quarks/13-intergenerational-barriers/ https://shipilev.net/jvm/anatomy-quarks/13-intergenerational... And there are a lot of other interesting posts on Java internals in that series.
- andrewchambers 5y agoFull heap scans still happen, just not as often, then you get the alternative 'cringe' of having huge amounts of old data sitting idle for nondeterministic periods of time.
- beagle3 5y agoLobster isn’t a new language - it’s probably a decade old by now - although this GC system is relatively recent (3 years or so, I think) Nim switched to a similar GC system recently, arc/orc ; And iiuc, this is similar to rust’s borrow checker - except you get an ref increase/decrease instead of a compile time error (if the compiler cannot prove references are unique).