Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vittorioromeo opened this issue Sep 28, 2024 · 0 comments
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@vittorioromeo
Copy link

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?

@EugeneZelenko EugeneZelenko added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants