• Tim Peters's avatar
    PyNode_AddChild(): Do aggressive over-allocation when the number of · 755ebea2
    Tim Peters yazdı
    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.
    755ebea2
node.c 2.32 KB