c los efficiency instantiation
play

C LOS Efficiency: Instantiation Experiments C++ L ISP Structures - PowerPoint PPT Presentation

Efficiency of Instantiation Didier Verna Introduction C LOS Efficiency: Instantiation Experiments C++ L ISP Structures Didier Verna Classes X-Comp Conclusion didier@lrde.epita.fr http://www.lrde.epita.fr/didier Perspectives Thanks!


  1. Efficiency of Instantiation Didier Verna Introduction C LOS Efficiency: Instantiation Experiments C++ L ISP Structures Didier Verna Classes X-Comp Conclusion didier@lrde.epita.fr http://www.lrde.epita.fr/˜didier Perspectives Thanks! ILC 2009 – Tuesday, March 20th 1/36

  2. The context Efficiency of Instantiation Don’t look at me. . . like that Didier Verna Not (particularly) interested in performance Introduction Not (at all) a L ISP implementer Experiments C++ ◮ Merely an observer L ISP Structures Classes Look at me. . . like this X-Comp Surrounded by C++ gurus (Cf. Olena ) Conclusion Performance does matter to them Perspectives Thanks! But you should see the code ! ◮ This would be so much easier in L ISP , but. . . 2/36

  3. They wouldn’t dare to complain about parens. . . Because if you can read this, Efficiency of Instantiation template <template <class> class M, typename T, typename V> Didier Verna struct ch_value_ <M <tag::value_<T>>, V> { typedef M<V> ret; }; Introduction Experiments template <template <class> class M, typename I, typename V> C++ struct ch_value_ <M <tag::image_<I>>, V> { typedef M <mln_ch_value(I, V)> ret; }; L ISP Structures Classes template <template <class, class> class M, typename T, X-Comp typename I, typename V> struct ch_value_ <M <tag::value_<T>, tag::image_<I>>, V> Conclusion { typedef mln_ch_value(I, V) ret; }; Perspectives Thanks! template <template <class, class> class M, typename P, typename T, typename V> struct ch_value_ <M <tag::psite_<P>, tag::value_<T>>, V> { typedef M<P, V> ret; }; 3/36

  4. They wouldn’t dare to complain about parens. . . surely you can read that ! Efficiency of Instantiation (template (template (class) (class M) (typename T) (typename V)) Didier Verna (struct (ch_value_ (M (tag::value_ T)) V) ( typedef (M V) ret)) ) Introduction Experiments (template (template (class) (class M) (typename I) (typename V)) C++ (struct (ch_value_ (M (tag::image_ I)) V) ( typedef (M (mln_ch_value I V)) ret)) ) L ISP Structures Classes (template (template (class class) (class M) (typename T) X-Comp (typename I) (typename V)) (struct (ch_value_ (M (tag::value_ T) (tag::image_ I)) V) Conclusion ( typedef (mln_ch_value I V) ret)) ) Perspectives Thanks! (template (template (class class) (class M) (typename P) (typename T) (typename V)) (struct (ch_value_ (M (tag::psite_ P) (tag::value_ T)) V) ( typedef (M P V) ret)) ) 4/36

  5. The performance “issue” Efficiency of Instantiation Typical conversation Didier Verna Yobbo: But L ISP is slow right? Introduction Me: How do you know that? Experiments Yobbo: [choose your favorite answer] C++ ✗ Huh, it’s a well known fact L ISP Structures ✗ Well, that’s what I heard Classes ✗ Last time I checked [. . . ] X-Comp ✓ It’s dynamic, so it’s slow Conclusion Perspectives Thanks! The real problems Lack of strong evidence (don’t know / don’t care) From the ground up (micro-benchmarking) ◮ Where are we today in terms of performance? 6/36

  6. My (not so) secret agenda On the behavior and performance of L ISP Efficiency of Instantiation Didier Verna Introduction Experiments C++ Meta−Programming (?) Dedication L ISP The ELW’06 Paper Structures Classes X-Comp Conclusion Dynamic OO You Perspectives Are Thanks! Here Instantiation Slot Access Generic Dispatch 7/36

  7. Table of contents Efficiency of Instantiation Didier Verna The experiments 1 Introduction Experiments C++ Grounding C++ 2 L ISP Structures Classes L ISP surprises 3 X-Comp Structures Conclusion Classes Perspectives Thanks! Cross-language comparison 4 8/36

  8. Experimental protocol Efficiency of Instantiation Class *instance = new Class; Didier Verna (make-instance ...) Introduction Experiments � = compilers C++ Class size (1, 7, 49 slots) L ISP Structures Class hierarchy (plain, vertical, horizontal) Classes X-Comp Slot type (fixnums, single-floats) Conclusion Slot initialization (yes, no) Perspectives Thanks! Slot allocation (instance, class) Optimization level (safe, optimized, inline) ◮ 1300+ individual tests 10/36

  9. Compilers Efficiency of C++: GCC 4.3.2 (Debian package 4.3.2-1) Instantiation Didier Verna L ISP : ◮ C MU - CL 19d (Debian package) Introduction ◮ S BCL 1.0.22.17 Experiments ◮ A CL 8.1 Express Edition C++ L ISP Structures Classes X-Comp Conclusion Perspectives Thanks! 11/36

  10. Class hierarchies Efficiency of Instantiation Plain Vertical Horizontal Didier Verna Class Class N+1 Class 1 Class 2 Class N Introduction ... −− slot 1 slot 2 slot N slot 1 Experiments slot 2 ... C++ slot N Class 1 L ISP slot 1 Structures Class N+1 Classes −− X-Comp Conclusion Class 2 slot 2 Perspectives Thanks! ... Class N slot N 13/36

  11. Slot initialization / allocation Efficiency of Instantiation Initialization Didier Verna Compile-time constants Introduction L ISP : :initform only Experiments C++: inside a provided constructor with no argument C++ L ISP Structures Shared slots Classes X-Comp C++: strictly compile-time Conclusion L ISP : run-time, but hopefully during class finalization or Perspectives first instance creation Thanks! 15/36

  12. Optimization modes Efficiency of Instantiation C++ Didier Verna -O3 -DNDEBUG Introduction Experiments L ISP C++ Not inlined: (make-instance some-class) L ISP ◮ “safe”: (safety 3) (... Structures 0) Classes ◮ “optimized”: (speed 3) (... 0) X-Comp “inline”: Conclusion ◮ “optimized” settings Perspectives ◮ (make-instance ’myclass) Thanks! 17/36

  13. Final remarks Efficiency of Instantiation structures vs classes Didier Verna C++: struct ⇐ ⇒ class Introduction L ISP : struct � = class Experiments C++ Meta-classes L ISP Structures L ISP -specific Classes X-Comp Conclusion Memory management Perspectives C++: manual Thanks! L ISP : automatic through (different) GC ◮ Avoid benchmarking 18/36

  14. Experimental conditions Efficiency of Debian GNU Linux / 2.6.26-1-686 packaged kernel Instantiation Didier Verna i686 DualCore C PU Introduction ◮ 2.13GHz Experiments ◮ 2GB RAM C++ ◮ 2MB level 2 cache L ISP Single user mode Structures Classes All benchmarks at least 1s X-Comp Conclusion Avoid memory exhaustion / swapping (C++) Perspectives ◮ 10% significance margin Thanks! 20/36

  15. C++ Results 5,000,000 objects, local slots Efficiency of Instantiation 4s Didier Verna Safe Optimized Introduction Experiments 3s C++ L ISP Structures Classes 2s X-Comp Conclusion float horz. hierarchy float vert. hierarchy Perspectives int horz. hierarchy int vert. hierarchy float plain class horz. hierarchy vert. hierarchy Thanks! int plain class 1s plain class 0s no slot 1 slot 7 slots 49 slots 22/36

  16. C++ behavior Efficiency of Immune to slot type Instantiation Didier Verna Optimization mode flattens timings ◮ Small effect of initialization remains Introduction Experiments Safe mode very sensitive to: C++ ◮ Slot initialization L ISP ◮ Class hierarchy Structures Classes ◮ Morphology of constructor call chain X-Comp Shared slots: all flat Conclusion Perspectives Thanks! 23/36

  17. L ISP structure results 10,000,000 objects, inline mode Efficiency of Instantiation 4s Didier Verna CMUCL ACL Introduction SBCL Experiments 3s C++ L ISP Structures Classes single-float plain struct single-float hierarchy 2s X-Comp Conclusion fixnum plain struct fixnum hierarchy Perspectives Thanks! plain struct 1s hierarchy 0s no slot 1 slot 7 slots 49 slots 25/36

  18. L ISP structure behavior Efficiency of Dependence on slot type Instantiation Didier Verna Internal representation / (un)boxing Immune to ( fixnum ) slot initialization Introduction Experiments Slots always initialized to nil (not required) C++ Immune to structure hierarchy L ISP struct ⇐ ⇒ vector Structures Classes X-Comp Discrepancies Conclusion Type checking: Perspectives ◮ C MU - CL : always (except fixnums in 19d) Thanks! ◮ S BCL : depends on compiler settings ◮ A CL : never C MU - CL on single-float ??? 26/36

  19. L ISP class results S BCL , 5,000,000 objects, standard class, local slots Efficiency of Instantiation 100s Didier Verna Safe fixnum horz. hierarchy fixnum vert. hierarchy Optimized Introduction float horz. hierarchy float vert. hierarchy fixnum plain class Inline float plain class Experiments horz. hierarchy vert. hierarchy C++ plain class 10s L ISP Structures Classes X-Comp Conclusion Perspectives 1s Thanks! 0.1s no slot 1 slot 7 slots 49 slots 28/36

  20. L ISP class behavior Efficiency of Immune to slot type / class hierarchy Instantiation Didier Verna No special representation, instance vector lookup + access Introduction Experiments Slots always initialized (secret unbound value) C++ But only slot access time visible L ISP Inline mode: (make-instance ’class) Structures Classes Improvement 15x to 100x !! X-Comp Shared slots: all flat Conclusion Bug (fixed): dependent on class size Perspectives Thanks! 29/36

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend