[all-commits] [llvm/llvm-project] 34b2e9: [libc++] Introduce `__product_iterator_traits` and...

Hui via All-commits all-commits at lists.llvm.org
Sat Jun 28 05:43:11 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 34b2e934ea9ec7a8b6529a9d0764c1bf3536b1d2
      https://github.com/llvm/llvm-project/commit/34b2e934ea9ec7a8b6529a9d0764c1bf3536b1d2
  Author: Hui <hui.xie1990 at gmail.com>
  Date:   2025-06-28 (Sat, 28 Jun 2025)

  Changed paths:
    M libcxx/docs/ReleaseNotes/21.rst
    M libcxx/include/CMakeLists.txt
    M libcxx/include/__flat_map/key_value_iterator.h
    M libcxx/include/__flat_map/utils.h
    A libcxx/include/__iterator/product_iterator.h
    M libcxx/include/__ranges/zip_view.h
    M libcxx/include/module.modulemap.in
    M libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
    M libcxx/test/benchmarks/containers/associative/flat_map.bench.cpp
    M libcxx/test/benchmarks/containers/associative/flat_multimap.bench.cpp
    A libcxx/test/libcxx/iterators/product_iterator.pass.cpp
    M libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_iter.pass.cpp

  Log Message:
  -----------
  [libc++] Introduce `__product_iterator_traits` and optimise `flat_map::insert` (#139454)

Fixes #108624

This allows `flat_map::insert(Iter, Iter)` to directly forward to
underlying containers' `insert(Iter, Iter)`, instead of inserting one
element at a time, when input models "product iterator". atm,
`flat_map::iterator` and `zip_view::iterator` are "product iterator"s.

This gives about almost 10x speed up in my benchmark with -03 (for both
before and after)

```cpp
Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
flat_map::insert_product_iterator_flat_map/32                   -0.5028         -0.5320           149            74           149            70
flat_map::insert_product_iterator_flat_map/1024                 -0.8617         -0.8618          3113           430          3112           430
flat_map::insert_product_iterator_flat_map/8192                 -0.8877         -0.8877         26682          2995         26679          2995
flat_map::insert_product_iterator_flat_map/65536                -0.8769         -0.8769        226235         27844        226221         27841
flat_map::insert_product_iterator_zip/32                        -0.5844         -0.5844           162            67           162            67
flat_map::insert_product_iterator_zip/1024                      -0.8754         -0.8754          3427           427          3427           427
flat_map::insert_product_iterator_zip/8192                      -0.8934         -0.8934         28134          3000         28132          3000
flat_map::insert_product_iterator_zip/65536                     -0.8783         -0.8783        229783         27960        229767         27958
OVERALL_GEOMEAN                                                 -0.8319         -0.8332             0             0             0             0
```

---------

Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list