[Python-Dev] C API for gc.enable() and gc.disable()

Adam Olsen rhamph at gmail.com
Thu Jun 19 23:35:55 CEST 2008


On Thu, Jun 19, 2008 at 3:23 PM, Alexandre Vassalotti
<alexandre at peadrop.com> wrote:
> On Sun, Jun 1, 2008 at 12:28 AM, Adam Olsen <rhamph at gmail.com> wrote:
>> On Sat, May 31, 2008 at 10:11 PM, Alexandre Vassalotti
>> <alexandre at peadrop.com> wrote:
>>> Would anyone mind if I did add a public C API for gc.disable() and
>>> gc.enable()? I would like to use it as an optimization for the pickle
>>> module (I found out that I get a good 2x speedup just by disabling the
>>> GC while loading large pickles). Of course, I could simply import the
>>> gc module and call the functions there, but that seems overkill to me.
>>> I included the patch below for review.
>>
>> I'd rather see it fixed.  It behaves quadratically if you load enough
>> to trigger full collection a few times.
>>
>
> Do you have any idea how this behavior could be fixed? I am not a GC
> expert, but I could try to fix this.

Not sure.  For long-running programs we actually want a quadratic
cost, but spread out over a long period of time.  It's the bursts of
allocation that shouldn't be quadratic.

So maybe balance it by the total number of allocations that have
happened.  If the total number of allocations is less than 10 times
the allocations that weren't promptly deleted, assume it's a burst.
If it's more than 10 times, assume it's over a long period.


-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-Dev mailing list