<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/110367>110367</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Should libcpp functions such as `std::array::operator[]` be marked `always_inline`?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vittorioromeo
      </td>
    </tr>
</table>

<pre>
    The recent article ["std::array in C++ isn't slower than array in C"](https://pvs-studio.com/en/blog/posts/cpp/1164/) measures `std::array` accesses having a significant run-time overhead with optimizations disabled, which is the norm for debug builds.

This is nothing new -- especially among the game developer community, the use of Standard Library abstractions such as `std::array` and `std::vector` is frowned upon due to their run-time overhead in debug builds.

A possible solution to debug overhead of containers such as `std::array` would be marking operations that (1) are commonly used in hot loops and (2) are simple/trivial as `_LIBCPP_ALWAYS_INLINE`. An example is [`std::array::operator[]`](https://github.com/llvm/llvm-project/blob/main/libcxx/include/array#L347-L355).

Would it make sense to mark such functions with with `_LIBCPP_ALWAYS_INLINE`? 

I cannot really think of any realistic drawback. Even with libcpp assertions enabled, I cannot think of a reasonable situation where all the following conditions apply:

1. I'm building with optimizations disabled
2. I'm building with Standard Library assertions enabled
3. I care about code size so much that I cannot afford an extra unlikely branch + jump per `std::array` access

So the potentially increased code size wouldn't be an issue in practice. Thoughts?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1v2zoQ_DX0ZRFDovx50MFpayBAUBRIgeKdghW5srahSIEfdt1f_0AqTVM07cO7KIHJXc4MZ5YYAp8sUSvWt2L9foEpDs63Z47ReXbejeQWndPX9vNA4EmRjYA-sjIEuUbKELVoDqI5oPd4BbbwTshbIW-BgxVyGyEYdyEPcUALrzdJsX4v5G6IcQq5hTwKeZzO4SbEpNktlRuFPJIV8tgZd8qLLsQg5FFNk5DHut6sStEeRsKQ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