How strongly does polymorphism affect performance and is it taken into account in serious software and computing systems?

  • 0
    How strongly polymorphism affects performance and is it taken into account in serious software and computing systems
    C++ Audrey Nash, Mar 9, 2020

  • 3 Answers
  • 0
    Everything counts in serious)))

    Actually, not much.

    A smart compiler optimizes calls when it can resolve types at compilation, and if it can't, how do you go around this when writing a program?

  • 0
    Overhead virtual functions, misches and more. But here is such a situation that if you have not encountered them, then most likely you will not come across them.

  • 0
    Polymorphism itself affects the level of error.

    The architecture without it may be so less optimal that it will slow down much more.

    In my experience of optimizing the computational work of a program in terms of speed, the main problem is to count exactly what is needed. If variants are calculated, then filtering them out at the earliest possible stage is such a trump card that beats any other optimization.

    The second is working with memory. Creating an array of objects in a nested loop in a recursive function will easily lay the entire top500% on its side) Not to mention that the probability of leakage is directly proportional to the number of dynamically created objects.

    And polymorphism ... well, if your actually polymorphic function is called a million times per second, you will probably feel a drop in performance ...

    In general, it seems to me that optimization should be done in the opposite direction. First - the architecture, in which the algorithms work will be clear and obviously optimal, then - the search for bottlenecks. If one day it gets to the point where polymorphic function calls become the bottleneck ... well, congratulations - learn assembler!
    Michael Kidd

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!