[libcxx-commits] [libcxx] [NFC][libc++][string] Improve constexpr efficiency (PR #184724)

Vitaly Buka via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 13 10:05:39 PDT 2026


vitalybuka wrote:

Actually never thought about speed, but for:

```
#include <array>
#include <string>
#ifndef N
#define N 1000
#endif
consteval auto eval() {
  std::array<std::string, N> r;
  for (auto& s : r) {
    s = "hello";
  }
  return r[0].size();
}
int main() {
  return eval();
}
```

`time bin/clang++   -std=c++20 -stdlib=libc++  -fconstexpr-steps=100000000 -DN=20000   test.cpp`

It's 25% faster with pr: 0m4.548s vs 0m5.942s

And I don't think constexpr array of 1000 elements is too artificial.

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


More information about the libcxx-commits mailing list