jemalloc/jemalloc — pull request #152 by thestinger (2014-10-16 22:56:31+00:00)
Title: add a version of rallocx taking old and used sizes

I'm not sure if you want this functionality, but I think it fits in well with `sdallocx` and it would be very useful in the guts of a vector / string implementation. It's actually a bit less intrusive than `sdallocx` was because the existing `arena_ralloc` / `huge_ralloc` functions get reused (~110 extra lines of code outside of docs / tests).

The usage of sized deallocation is a small performance increase for the first few resizes and the `used` parameter provides a performance increase for string / vector concatenation through all of the size classes for implementations with geometric growth.

When Rust can't do a vector / string append in-place, it calculates the required size and rounds that up to the next power of 2 to avoid repeated reallocations in a loop. The vector / string will often have a significant amount of space at the end that's not large enough for the next append. The performance improvement from the `used` parameter alone in concatenation is anywhere in 0-40% range depending on the specific sizes involved. I haven't yet measured the impact is on a real-world string manipulation workload.

There's not much point in doing the optimization for `xalloc` because it can't benefit from a `used` size parameter and it will *always* fail to resize small allocations in-place. It would only make the code path for no-op reallocations significantly faster and the caller could already avoid that size lookup by calling `nallocx`.