[libcxx-commits] [libcxx] [libc++] Optimize string operator[] for known large inputs (PR #69500)

Ilya Tocar via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 24 16:19:40 PDT 2023


TocarIP wrote:

For mixed index and following code
```
  void BM_index(benchmark::State& state) {
    for (auto _ : state) {
      for (int i = 0;i<21;i++) {
        testing::DoNotOptimize(s[33]*37+s[i]);
      }   
    }
  }

```
I see speed up from `BM_index  15.5ns ±15%` to `BM_index  13.6ns ±16%`
Non-constant index are obviously unchanged (`16.0ns ±11%` vs `BM_index  16.3ns ±10%`).
Overall its hard to write benchmarks when I don't have a good mental model for a possible regression. Do you have a specific concern in mind? Only code path with constant index is affected and removing branches seems like an obviously good thing (modulo code-alignment shenanigans).

https://github.com/llvm/llvm-project/pull/69500


More information about the libcxx-commits mailing list