Skip to content

Should libcpp functions such as std::array::operator[] be marked always_inline? #110367

Open
@vittorioromeo

Description

@vittorioromeo

The recent article "std::array in C++ isn't slower than array in C" 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[].

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions