Refactor Conditionals into Polymorphism: What's the Performance Cost of Introducing Virtual Calls?

  • Authors:
  • Serge Demeyer

  • Affiliations:
  • University of Antwerp

  • Venue:
  • ICSM '05 Proceedings of the 21st IEEE International Conference on Software Maintenance
  • Year:
  • 2005

Quantified Score

Hi-index 0.00

Visualization

Abstract

The notion of refactoring 驴 transforming the source-code of an object-oriented program without changing its external behavior 驴 has been embraced by many object-oriented software developers as a way to accommodate changing requirements. If applied well, refactoring improves the maintainability of the software. However, it is believed that it does so at the sake of performance. Especially in a C++ context, the introduction of virtual function calls is often blamed for performance reduction because it introduces an extra indirection via the so-called virtual function table. To investigate the performance trade-off involved when introducing virtual functions, we compared the execution time of four benchmark programs which contain large conditionals against refactored versions where the conditionals were replaced by virtual function calls. Depending on the compiler and compiler optimizations being used, we discovered that C++ programs refactored this way often perform faster than their non-refactored counterparts, hence advise programmers not to obfuscate their programs with conditional logic in order to obtain good performance.