Fields

hardware None
os None

Parameters

Fields

NameValue

Parameters

NameValue
git_commit commit 31824b2a11a8aa3e1d5c699cd0786ad666999abf
Author: Peng Liu <winner245@hotmail.com>
Date: Sat Feb 22 08:50:48 2025 -0500

[libc++] Fix shrink_to_fit to swap buffer only when capacity is strictly smaller (#127321)

The current implementation of the `shrink_to_fit()` function of
`basic_string` swaps to the newly allocated buffer when the new buffer
has the same capacity as the existing one. While this is not incorrect,
it is truly unnecessary to swap to an equally-sized buffer. With equal
capacity, we should keep using the existing buffer and simply deallocate
the new one, avoiding the extra work of copying elements.

The desired behavior was documented in the following comment within the
function:


https://github.com/llvm/llvm-project/blob/61ad08792a86e62309b982189a600f4342a38d91/libcxx/include/string#L3560-L3566

However, the existing implementation did not exactly conform to this
guideline, which is a QoI matter.

This PR modifies the `shrink_to_fit()` function to ensure that the
buffer is only swapped when the new allocation is strictly smaller than
the existing one. When the capacities are equal, the new buffer will be
discarded without copying the elements. This is achieved by including
the `==` check in the above conditional logic.
Filter

ldionne-old-macbook-results test results

Run Order Start Time Duration
Current 528215 2025-12-16T16:40:01 0:00:00
Previous 528790 2025-12-16T16:40:01 0:00:00
Baseline 485288 2025-12-16T16:40:01 0:00:00


Tests Summary

Status Group # # (B)
Performance Improvements 3 0
Added Tests 0 18
Unchanged Tests 87 72
Total Tests 90

Performance Improvements - execution_time Δ Previous Current σ Δ (B) σ (B)
710_omnetpp_r -4.74% 8.751 8.337 0.127 0.00% 0.127
707_ntest_r -2.21% 18.469 18.062 0.064 0.00% 0.064
734_vpr_r -2.00% 15.626 15.314 0.067 0.00% 0.067

Added Tests - execution_time
706_stockfish_r
707_ntest_r
709_cactus_r
710_omnetpp_r
721_gcc_r
723_llvm_r
727_cppcheck_r
729_abc_r
731_astcenc_r
734_vpr_r
735_gem5_r
736_ocio_r
737_gmsh_r
748_flightdm_r
750_sealcrypto_r
753_ns3_r
766_femflow_r
767_nest_r


Report Time: 0.09s
Name Current %
706_stockfish_r 22.109 -
707_ntest_r 18.062 -2.21%
709_cactus_r 19.639 -
710_omnetpp_r 8.337 -4.74%
721_gcc_r 12.974 -
723_llvm_r 11.525 -
727_cppcheck_r 25.001 -
729_abc_r 18.654 -
731_astcenc_r 10.037 -
734_vpr_r 15.314 -2.00%
735_gem5_r 13.878 -
736_ocio_r 16.285 -
737_gmsh_r 13.000 -
748_flightdm_r 8.878 -
750_sealcrypto_r 18.385 -
753_ns3_r 10.625 -
766_femflow_r 12.813 -
767_nest_r 14.211 -
Geometric Mean 14.331 -