Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mrs_realloc: avoid copies when space is available
When the passed pointer is valid and already has enough space, return it unless it's at least twice the requested size. Some software uses realloc to extend allocations by small, fixed amounts. In a naive implementation of realloc that blindly performs a new allocation, copies the data, and then frees the old allocation, this is O(n^2). For small values of `n` this isn't too noticable, but asymptotically it's quite bad and revocation makes it much worse. With current tuning, we eventually reach a point where approximately every 4th allocation triggers a revocation pass. We can make this somewhat less visible (or fix it entirely for snmalloc with it's power-of-two sized buckets) by omitting unnecessary allocations and copies. Bias towards improving linear increase performance over space saving and only reallocate to shrink the allocation if we'd save at least 50% space. If we chose a smaller value then we end up doing full reallocs constantly with an allocator like snmalloc.
- Loading branch information