Next: INTRODUCTION Up: bkuhn's Technical Writings


Bradley M. Kuhn1
- David W. Binkley1

Computer Science Department
Loyola College in Maryland
4501 N. Charles Street
Baltimore, Maryland 21210-2699

Keywords Virtual Functions, Optimization, Dynamic Binding


Gaining the code re-use advantages of object oriented programming requires dynamic function binding, which allows a new subclass to override a function of a superclass. Dynamic binding is obtained in C++ through the use of virtual functions. Unfortunately, virtual functions have two negative impacts on performance. First, they are traditionally compiled into indirect call instructions, which take longer to execute than direct call instructions. Second, it is difficult for the compiler to perform optimization since summary information from called procedures is hard or even impossible to obtain. The net effect is that C++ programmers avoid the use of virtual functions.

We present a new optimization that (1) removes the indirect function calls used for virtual functions, (2) enables other compiler optimizations such as inlining and constant propagation, and (3) requires no extensive data-flow analysis or profile information and thus is easily implemented in an existing compiler. We include experimental evidence that this optimization reduces execution time. Not surprisingly, the greatest benefits are obtained with programs that include a high proportion of virtual functions calls.

Next: INTRODUCTION Up: bkuhn's Technical Writings

Copyright © 1995, 1996 Bradley M. Kuhn, David W. Binkley.

Verbatim copying and distribution of this entire paper is permitted in any medium, provided this notice is preserved.