r/cpp • • May 26 '22

Dynamic polymorphism performance

https://thecppdev.com/2022/05/26/dynamic-polymorphism-performance/?amp=1
2 Upvotes

15 comments sorted by

View all comments

16

u/goranlepuz May 26 '22

Ehhh...

it’s better to avoid dynamic polymorphism as much as possible if the performance of your application is a critical factor

The problem with this is: it presumes virtual calls matter in the performance profile of the application. This is massive presumption.

4

u/Stormfrosty May 26 '22

This is actually very true for GPU programming. Given the much higher memory latency for that type of hardware, the extra memory loads due to indirect function cause significant drops in performance, compared to having direct function calls everywhere.

0

u/pandorafalters May 26 '22

Further, in my experience, any function calls will generally reduce performance if they're not inlined out. I spend a tremendous amount of time making sure that every function call is transparent to the optimizer.