It's not uncommon for up to 1/3 of usage and therefore the bill on VMs in the cloud to be consumed by garbage collection. So if you can rewrite it without a garbage collector, you can save money. A great book on this topic is "The Beast Is Back" by jetbrains. Advocating C++ in that case (written in 2015). If GC makes you more productive, that's good, but at some point rewriting things without GC makes sense.
stcredzero|6 years ago
Save money over what? It's usually a lot easier to optimize memory use than to rewrite code. Going by the 80/20 rule, 80% of the memory pressure on the GC will be created by 20% of the code. So amortize the price of the rewrite over the expected lifespan of the app. Then compare this to, let's say, the cost of optimizing 10% of the app to eliminate 40% of the memory pressure. Then, also factor in the likely rate of bugs introduced in a rewrite compared to the optimizing GC and the cost of incurring, finding, and fixing those bugs.
Going by this analysis, I would suspect that in some environments where rapid iteration is key, progress is fast, and apps have short lifespans, it might be better to optimize GC instead of rewrite to eliminate it. I'd also expect that in other cases, it is better to rewrite to eliminate GC.
ncmncm|6 years ago
So, the analysis of GC overhead is always going to pit cost X against cost zero, no matter how low you manage to get X.
icebraining|6 years ago
ncmncm|6 years ago
The fraction of runtime involving allocation and deallocation, at the level where they happen, is typically negligible. In servers, after program startup, it is often (and deliberately) exactly zero.
weberc2|6 years ago
ncmncm|6 years ago
And, the answer is that real programs in obligate-GC languages spend overwhelmingly more time in GC than C++ or Rust. Much of this time is spent waiting on cache misses, which are hard to track to the responsible bit of code.
vardump|6 years ago
That's actually true, as long as all things are equal. GC can amortize memory management cost. Of course at cost of more jitter.
Unfortunately many GC language users tend to do way more allocations as well, diminishing the advantage and even turning it into negative.
codesushi42|6 years ago
That's not really true anymore after the introduction of smart pointers. Basically C++ implements reference counting to manage memory as a result.