Subject: Re: bug#37006: 27.0.50; garbage collection not happening after 26de2d42

From: Eli Zaretskii <[email-masked]>
Date: Thu, 15 Aug 2019 22:34:27 +0300

> Cc: [email-masked], [email-masked], [email-masked]
> From: Paul Eggert <[email-masked]>
> Date: Thu, 15 Aug 2019 11:51:06 -0700
> 
> > most-positive-fixnum on 32-bit systems is large enough for
> > every practical purpose.
> 
> It's not that hard for the number of consed bytes to exceed most-positive-fixnum 
> on a 32-bit Emacs. Here's a simple test case to illustrate the phenomenon:
> 
> (let* ((cons-size (car (cdr (car (garbage-collect)))))
>         (long-length (1+ (/ most-positive-fixnum cons-size)))
>         (l (make-list long-length nil)))
>    (cons most-positive-fixnum (* cons-size (length l))))
> 
> This yielded (536870911 . 536870912) on the 32-bit Emacs that I just built. Of 
> course a practical application would likely have a bunch of smaller lists, but 
> the same basic idea applies. On such a platform, a user who wants to disable GC 
> while fiddling with a bunch of large lists will need to set gc-cons-threshold to 
> a bignum.

I don't see why we must complicate our code to support such a use
case.  Users who want to disable GC while consing so much object will
have to learn that they cannot, not on a 32-bit machine.

> > supporting the full 32 bits (and 64
> > bits in 64-bit builds) will also allow contradictory situation whereby
> > gc-cons-threshold is higher than what we say should be used to disable
> > GC.
> 
> Sorry, I'm not following. If setting gc-cons-threshold to a large value 
> effectively disables GC, then setting gc-cons-threshold to a larger value should 
> do the same thing.

most-positive-fixnum is infinity for this purpose, and there should
not be numbers greater than infinity.  It's confusing and hard to
explain.

> > Why do we need to talk about how many objects are there?  GC threshold
> > is not about counting objects, it's about deciding when to GC.
> 
> The GC threshold is part of a related set of integers that count objects and 
> bytes, for use in the returned value of garbage-collect among other things.

No, they are just a means to decide when it's a good time to GC.  Very
large values are used to effectively disable GC, very small values to
cause GC "soon".  That's all, there are no requirements to count
objects or to have any accurate bookeeping of how many objects or
bytes were consed.

> > Are you working on that, or should someone else do it?
> 
> I can add it to my list of things to do. To my mind, getting the timestamp API 
> nailed down is more urgent, though, because fiddling with GC heuristics doesn't 
> affect the API.

Well, meanwhile we've broken a very popular use case, so I think
fixing this is rather urgent.

> > Right, but that's not what I proposed.  I proposed to trigger an
> > immediate GC only the first time we detect memory-full.  Thereafter,
> > the threshold will be set to 1KB, which should prevent thrashing.
> 
> Isn't it more complicated than that? Emacs can be low on memory, but can then 
> get more and not be low on memory, and then be low on memory again later.

Maybe so, but we had such code in Emacs for decades.  I just want to
avoid losing those features.