Given an array of length size that needs to be expanded to newlength,
compute a new capacity.
Better version by Dave Fladebo:
This uses an inverse logorithmic algorithm to pre-allocate a bit more
space for larger arrays.
- Arrays smaller than PAGESIZE bytes are left as-is, so for the most
common cases, memory allocation is 1 to 1. The small overhead added
doesn't affect small array perf. (it's virtually the same as
current).
- Larger arrays have some space pre-allocated.
- As the arrays grow, the relative pre-allocated space shrinks.
- The logorithmic algorithm allocates relatively more space for
mid-size arrays, making it very fast for medium arrays (for
mid-to-large arrays, this turns out to be quite a bit faster than the
equivalent realloc() code in C, on Linux at least. Small arrays are
just as fast as GCC).
- Perhaps most importantly, overall memory usage and stress on the GC
is decreased significantly for demanding environments.
Given an array of length size that needs to be expanded to newlength, compute a new capacity.
Better version by Dave Fladebo: This uses an inverse logorithmic algorithm to pre-allocate a bit more space for larger arrays. - Arrays smaller than PAGESIZE bytes are left as-is, so for the most common cases, memory allocation is 1 to 1. The small overhead added doesn't affect small array perf. (it's virtually the same as current). - Larger arrays have some space pre-allocated. - As the arrays grow, the relative pre-allocated space shrinks. - The logorithmic algorithm allocates relatively more space for mid-size arrays, making it very fast for medium arrays (for mid-to-large arrays, this turns out to be quite a bit faster than the equivalent realloc() code in C, on Linux at least. Small arrays are just as fast as GCC). - Perhaps most importantly, overall memory usage and stress on the GC is decreased significantly for demanding environments.