Advertisement

Eliminating virtual function calls in C++ programs

  • Gerald Aigner
  • Urs Hölzle
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 1098)

Abstract

We have designed and implemented an optimizing source-to-source C++ compiler that reduces the frequency of virtual function calls. Our prototype implementation demonstrates the value of OO-specific optimization for C++. Despite some limitations of our system, and despite the low frequency of virtual function calls in some of the programs, optimization improves the performance of a suite of large C++ applications totalling over 90,000 lines of code by a median of 18% over the original programs and reduces the number of virtual function calls by a median factor of five. For more call-intensive versions of the same programs, performance improved by a median of 26% and the number of virtual calls dropped by a factor of 17.5. Our measurements indicate that inlining barely increases code size, and that for most programs, the instruction cache miss ratio does not increase significantly.

Keywords

Original Program Parse Tree Receiver Class Instruction Cache Type Feedback 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. [Age95]
    Ole Agesen. The Cartesian Product Algorithm: Simple and Precise Type Inference of Parametric Polymorphism. In ECOOP'95, Ninth European Conference on Object-Oriented Programming, p. 2–26, århus, Denmark, August 1995. Springer-Verlag LNCS 952.Google Scholar
  2. [AH95]
    Ole Agesen and Urs Hölzle. Type Feedback vs. Concrete Type Inference: A Comparison of Optimization Techniques for Object-Oriented Languages. In OOPSLA'95, Object-Oriented Programming Systems, Languages and Applications, p. 91–107, Austin, TX, October 1995.Google Scholar
  3. [App88]
    Apple Computer, Inc. Object Pascal User's Manual. Cupertino, 1988.Google Scholar
  4. [B+96]
    David Bernstein, Yaroslav Fedorov, Sara Porat, Joseph Rodrigue, and Eran Yahav. Compiler Optimization of C++ Virtual Function Calls. 2nd Conference on Object-Oriented Technologies and Systems, Toronto, Canada, June 1996.Google Scholar
  5. [CGZ94]
    Brad Calder, Dirk Grunwald, and Benjamin Zorn. Quantifying Behavioral Differences Between C and C++ Programs. Journal of Programming Languages 2:313–351, 1994.Google Scholar
  6. [CG94]
    Brad Calder and Dirk Grunwald. Reducing Indirect Function Call Overhead in C++ Programs. In 21st Annual ACM Symposium on Principles of Programming Languages, p. 397–408, January 1994.Google Scholar
  7. [CUL89]
    Craig Chambers, David Ungar, and Elgin Lee. An Efficient Implementation of SELF, a Dynamically-Typed Object-Oriented Language Based on Prototypes. In OOPSLA '89, Object-Oriented Programming Systems, Languages and Applications, p. 49–70, New Orleans, LA, October 1989. Published as SIGPLAN Notices 24(10), October 1989.CrossRefGoogle Scholar
  8. [CU90]
    Craig Chambers and David Ungar. Iterative Type Analysis and Extended Message Splitting: Optimizing Dynamically-Typed Object-Oriented Programs. In Proceedings of the SIGPLAN '90 Conference on Programming Language Design and Implementation, p. 150–164, White Plains, NY, June 1990. Published as SIGPLAN Notices 25(6), June 1990.CrossRefGoogle Scholar
  9. [CM+92]
    Pohua P. Chang, Scott A. Mahlke, William Y. Chen, and Wen-Mei W. Hwu. Profile-guided automatic inline expansion for C programs. Software—Practice and Experience 22 (5): 349–369, May 1992.Google Scholar
  10. [CHT91]
    K. D. Cooper, M. W. Hall, and L. Torczon. An experiment with inline substitution. Software—Practice and Experience 21 (6): 581–601, June 1991.Google Scholar
  11. [DH88]
    Jack W. Davidson and Anne M. Holler. A study of a C function inliner. Software—Practice and Experience 18(8): 775–90, August 1988.Google Scholar
  12. [DC94]
    Jeffrey Dean and Craig Chambers. Towards Better Inlining Decisions using Inlining Trials. In Proceedings of the ACM Symposium on Lisp and Functional Programming Languages (LFP '94), Orlando, FL, June 1994.Google Scholar
  13. [DCG95]
    Jeffrey Dean, Craig Chambers, and David Grove. Identifying Profitable Specialization in Object-Oriented Languages. In Proceedings of the SIGPLAN '95 Conference on Programming Language Design and Implementation, La Jolla, CA June 1995.Google Scholar
  14. [DGC95]
    Jeffrey Dean, David Grove, and Craig Chambers. Optimization of Object-Oriented Programs Using Static Class Hierarchy Analysis. In ECOOP '95, Ninth European Conference on Object-Oriented Programming, århus, 1995. Springer-Verlag LNCS 952.Google Scholar
  15. [Dea95]
    Jeffrey Dean. Corrected Cecil performance numbers. Private communication, May 1995.Google Scholar
  16. [Dec95]
    Declarative Systems. The C++ Auditor. Palo Alto, 1995. (auditor@declarative.com)Google Scholar
  17. [DHV95]
    Karel Driesen, Urs Hölzle, and Jan Vitek. Message Dispatch On Pipelined Processors. ECOOP '95 Conference Proceedings, Aarhus, Denmark, August 1995. Published as Springer Verlag Lecture Notes in Computer Science 952, Springer Verlag, Berlin, 1995.Google Scholar
  18. [DS84]
    L. Peter Deutsch and Alan Schiffman. Efficient Implementation of the Smalltalk-80 System. In Conference Record of the Eleventh Annual ACM Symposium on Principles of Programming Languages, p. 297–302, Salt Lake City, UT, January 1984.Google Scholar
  19. [Deu83]
    L. Peter Deutsch. Reusability in the Smalltalk-80 system. Workshop On Reusability In Programming, Newport, RI, 1983.Google Scholar
  20. [ES90]
    Margaret A. Ellis and Bjarne Stroustrup. The Annotated C++ Reference Manual. Addison-Wesley, Reading, MA, 1990.Google Scholar
  21. [Fer95]
    M. F. Fernandez. Simple and effective link-time optimization of Modula-3 programs. In Proceedings of the SIGPLAN '95 Conference on Programming Language Design and Implementation, p. 103–115, La Jolla, CA, June 1995. Published as SIGPLAN Notices 30(6), June 1995.CrossRefGoogle Scholar
  22. [G+95]
    David Grove, Jeffrey Dean, Charles D. Garrett, and Craig Chambers. Profile-Guided Receiver Class Prediction. In OOPSLA '95, Object-Oriented Programming Systems, Languages and Applications, p. 108–123, Austin, TX, October 1995.Google Scholar
  23. [Hall91]
    Mary Wolcott Hall. Managing Interprocedural Optimization. Technical Report COMP TR91-157 (Ph.D. Thesis), Computer Science Department, Rice University, April 1991.Google Scholar
  24. [HCU91]
    Urs Hölzle, Craig Chambers, and David Ungar. Optimizing Dynamically-Typed Object-Oriented Languages with Polymorphic Inline Caches. In ECOOP '91, Fourth European Conference on Object-Oriented Programming, p. 21–38, Geneva, July 1991. Springer-Verlag LNCS 512.Google Scholar
  25. [Höl94]
    Urs Hölzle. Adaptive Optimization for SELF: Reconciling High Performance with Exploratory Programming. Ph.D. Thesis, Department of Computer Science, Stanford University, August 1994. (Available via http://www.cs.ucsb.edu/~urs.)Google Scholar
  26. [HU94a]
    Urs Hölzle and David Ungar. Optimizing Dynamically-Dispatched Calls with Run-Time Type Feedback. In Proceedings of the SIGPLAN '94 Conference on Programming Language Design and Implementation, p. 326–336. Published as SIGPLAN Notices 29(6), June 1994.CrossRefGoogle Scholar
  27. [HwC89]
    W. W. Hwu and P. P. Chang. Inline function expansion for compiling C programs. In Proceedings of the SIGPLAN '89 Conference on Programming Language Design and Implementation, p. 246–57, Portland, OR, June 1989. Published as SIGPLAN Notices 24(7), July 1989.CrossRefGoogle Scholar
  28. [Knu70]
    Donald Knuth. An empirical study of FORTRAN programs. Technical Report CS-186, Department of Computer Science, Stanford University, 1970.Google Scholar
  29. [Lea90]
    Douglas Lea. Customization in C++. In Proceedings of the 1990 Usenix C++ Conference, p. 301–314, San Francisco, CA, April, 1990.Google Scholar
  30. [PR94]
    Hemant D. Pande and Barbara G. Ryder. Static Type Determination and Aliasing for C++. Technical Report LCSR-TR-236, Rutgers University, December 1994.Google Scholar
  31. [PC94]
    John B. Plevyak and Andrew A. Chien. Precise Concrete Type Inference for Object-Oriented Languages. OOPSLA '94, Object-Oriented Programming Systems, Languages and Applications, p. 324–340, Portland, OR, October 1994. Published as SIGPLAN Notices 29(10), October 1994.CrossRefGoogle Scholar
  32. [Ser95]
    Mauricio Serrano. Virtual function call frequencies in C++ programs. Private communication, 1995.Google Scholar
  33. [SW92]
    Amitabh Srivastava and David Wall. A Practical System for Intermodule Code Optimization at Link-Time. DEC WRL Research Report 92/6, December 1992.Google Scholar
  34. [US87]
    David Ungar and Randall B. Smith. SELF: The Power of Simplicity. In OOPSLA '87, Object-Oriented Programming Systems, Languages and Applications, p. 227–241, Orlando, FL, October 1987. Published as SIGPLAN Notices 22(12), December 1987. Also published in Lisp and Symbolic Computation 4(3), Kluwer Academic Publishers, June 1991.CrossRefGoogle Scholar
  35. [Wall91]
    David Wall. Predicting Program Behavior Using Real or Estimated Profiles. In Proceedings of the SIGPLAN '91 Conference on Programming Language Design and Implementation, p. 59–70, Toronto, Canada, June 1991. Published as SIGPLAN Notices 26(6), June 1991.CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1996

Authors and Affiliations

  • Gerald Aigner
    • 1
  • Urs Hölzle
    • 1
  1. 1.Computer Science DepartmentUniversity of CaliforniaSanta Barbara

Personalised recommendations