Fields

hardware None
os None

Parameters

Fields

NameValue

Parameters

NameValue
git_commit commit 056153f36eca184f81969f5cd5c8cd967c935f96
Author: Peng Liu <winner245@hotmail.com>
Date: Thu Nov 28 14:52:59 2024 -0500

Optimize vector::assign for InputIterator-only pair inputs (#113852)

This PR optimizes the input iterator overload of `assign(_InputIterator,
_InputIterator)` in `std::vector<_Tp, _Allocator>` by directly assigning
to already initialized memory, rather than first destroying existing
elements and then constructing new ones. By eliminating unnecessary
destruction and construction, the proposed algorithm enhances the
performance by up to 2x for trivial element types (e.g.,
`std::vector<int>`), up to 2.6x for non-trivial element types like
`std::vector<std::string>`, and up to 3.4x for more complex non-trivial
types (e.g., `std::vector<std::vector<int>>`).

### Google Benchmarks

Benchmark tests (`libcxx/test/benchmarks/vector_operations.bench.cpp`)
were conducted for the `assign()` implementations before and after this
patch. The tests focused on trivial element types like
`std::vector<int>`, and non-trivial element types such as
`std::vector<std::string>` and `std::vector<std::vector<int>>`.



#### Before
```
-------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
-------------------------------------------------------------------------------------------------
BM_AssignInputIterIter/vector_int/1024/1024 1157 ns 1169 ns 608188
BM_AssignInputIterIter<32>/vector_string/1024/1024 14559 ns 14710 ns 47277
BM_AssignInputIterIter<32>/vector_vector_int/1024/1024 26846 ns 27129 ns 25925
```


#### After
```
-------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
-------------------------------------------------------------------------------------------------
BM_AssignInputIterIter/vector_int/1024/1024 561 ns 566 ns 1242251
BM_AssignInputIterIter<32>/vector_string/1024/1024 5604 ns 5664 ns 128365
BM_AssignInputIterIter<32>/vector_vector_int/1024/1024 7927 ns 8012 ns 88579
```
Filter

ldionne-old-macbook-results test results

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


Tests Summary

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

Performance Regressions - execution_time Δ Previous Current σ Δ (B) σ (B)
735_gem5_r 1.19% 13.525 13.687 - 0.00% -
721_gcc_r 1.09% 12.921 13.062 - 0.00% -

Performance Improvements - execution_time Δ Previous Current σ Δ (B) σ (B)
734_vpr_r -5.17% 16.455 15.605 - 0.00% -
748_flightdm_r -3.22% 9.163 8.867 - 0.00% -
766_femflow_r -2.14% 13.067 12.787 - 0.00% -

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.13s
Name Current %
706_stockfish_r 22.040 -
707_ntest_r 17.784 -
709_cactus_r 19.702 -
710_omnetpp_r 8.453 -
721_gcc_r 13.062 1.09%
723_llvm_r 11.524 -
727_cppcheck_r 24.819 -
729_abc_r 18.645 -
731_astcenc_r 10.025 -
734_vpr_r 15.605 -5.17%
735_gem5_r 13.687 1.19%
736_ocio_r 16.192 -
737_gmsh_r 12.949 -
748_flightdm_r 8.867 -3.22%
750_sealcrypto_r 18.394 -
753_ns3_r 10.282 -
766_femflow_r 12.787 -2.14%
767_nest_r 14.146 -
Geometric Mean 14.292 -