]> granicus.if.org Git - python/commit
PyNode_AddChild(): Do aggressive over-allocation when the number of
authorTim Peters <tim.peters@gmail.com>
Mon, 8 Jul 2002 06:32:09 +0000 (06:32 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 8 Jul 2002 06:32:09 +0000 (06:32 +0000)
commit755ebea23b8bac26661d3315ef68ccff61c55e6e
treee90a7c4ca920e169a7e3412d2986fadf1306a283
parent059ed83cc327d8f9404a160b7a5f9fb2c2b5b090
PyNode_AddChild():  Do aggressive over-allocation when the number of
children gets large, to avoid severe platform realloc() degeneration
in extreme cases (like test_longexp).

Bugfix candidate.

This was doing extremely timid over-allocation, just rounding up to the
nearest multiple of 3.  Now so long as the number of children is <= 128,
it rounds up to a multiple of 4 but via a much faster method.  When the
number of children exceeds 128, though, and more space is needed, it
doubles the capacity.  This is aggressive over-allocation.

SF patch <http://www.python.org/sf/578297> has Andrew MacIntyre using
PyMalloc in the parser to overcome platform malloc problems in
test_longexp on OS/2 EMX.  Jack Jansen notes there that it didn't help
him on the Mac, because the Mac has problems with frequent ever-growing
reallocs, not just with gazillions of teensy mallocs.  Win98 has no
visible problems with test_longexp, but I tried boosting the test-case
size and soon got "senseless" MemoryErrors out of it, and soon after
crashed the OS:  as I've seen in many other contexts before, while the
Win98 realloc remains zippy in bad cases, it leads to extreme
fragmentation of user address space, to the point that the OS barfs.

I don't yet know whether this fixes Jack's Mac problems, but it does cure
Win98's problems when boosting the test case size.  It also speeds
test_longexp in its unaltered state.
Parser/node.c