https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104719

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Vittorio Romeo from comment #4)
> I like the idea of having the compiler itself fold calls to things like
> `std::move` and `std::forward` as suggested in the linked
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96780. 

That benefits user code too, so that users won't have to use static_cast<T&&>
in their own code because "std::move is slow".

> But I think this issue I opened should be more general for any standard
> library function that ends up impacting debug performance. Another common
> example in the gamedev community is `std::vector`.

Does the gamedev community actually use -Og though? Because if they only use
-O0 (as is certainly the case for some) then the solution is "don't do that".
Do they even use GCC/libstdc++ at all? Would they actually be more likely to if
we change anything here?

For those who are using -Og, adding always_inline to trivial accessors
shouldn't be necessary, because GCC _should_ always inline them anyway.

> In this benchmark, which uses `-Og`, you can notice a large performance
> difference between a `std::vector<int>` and `int*` dynamic array for
> operations that I believe should have equal performance:
> - https://quick-bench.com/q/lrS4I-lmDJ3VFP8L8rG2YHGXO-8
> - https://quick-bench.com/q/Uf-t79n7uYWAKdThOL_wxSp12Y0
> 
> Are the above results also something that should be handled on the compiler
> side of things? Or would, for example, marking `std::vector::operator[]` and
> `std::vector::iterator::operator*` as `always_inline` remove the performance
> discrepancy?

Somebody will have to investigate whether lack of inlining is the problem
there. My guess would be that it's not due to trivial functions like op[]
failing to be inlined, and so always_inline wouldn't help (except at -O0, but
"don't do that" if you need performance :-)

Reply via email to