lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 4/14/19, Sean Conner <> wrote:
> What's wrong with __gc ?

please read

some quotes from this article/blog post:

So here’s what Apple has to say about ARC vs GC, when pressed:

    At the top of your wishlist of things we could do for you is
bringing garbage collection to iOS. And that is exactly what we are
not going to do… Unfortunately garbage collection has a suboptimal
impact on performance. Garbage can build up in your applications and
increase the high water mark of your memory usage. And the collector
tends to kick in at undeterministic times which can lead to very high
CPU usage and stutters in the user experience. And that’s why GC has
not been acceptable to us on our mobile platforms. In comparison,
manual memory management with retain/release is harder to learn, and
quite frankly it’s a bit of a pain in the ass. But it produces better
and more predictable performance, and that’s why we have chosen it as
the basis of our memory management strategy. Because out there in the
real world, high performance and stutter-free user experiences are
what matters to our users.

In particular, when garbage collection has five times as much memory
as required, its runtime performance matches or slightly exceeds that
of explicit memory management. However, garbage collection’s
performance degrades substantially when it must use smaller heaps.
With three times as much memory, it runs 17% slower on average, and
with twice as much memory, it runs 70% slower. Garbage collection also
is more susceptible to paging when physical memory is scarce. In such
conditions, all of the garbage collectors we examine here suffer
order-of-magnitude performance penalties relative to explicit memory

The ground truth is that in a memory constrained environment garbage
collection performance degrades exponentially.  If you write Python or
Ruby or JS that runs on desktop computers, it’s possible that your
entire experience is in the right hand of the chart, and you can go
your whole life without ever experiencing a slow garbage collector.

> What problem is only solved with reference counting ?

it releases resources ASAP, avoiding random stalls throughout script
execution and
thus provides a smoother runtime experience (games come to mind here).

there are algorithms that reduce these stalls
(incremental/generational garbage collection) but, given enough
objects, they will be noticeable again.