High Performance Erlang

6,863 views
6,637 views

Published on

Published in: Technology, News & Politics

High Performance Erlang

  1. 1. HiPE version 1.0 Kostis Sagonas Uppsala University
  2. 2. Structure of this talk <ul><li>1. Recent past </li></ul><ul><li>2. Present </li></ul><ul><li>3. Near future </li></ul>
  3. 3. Part 1: Recent Past
  4. 4. Historical introduction <ul><li>During the last few years, the following people: </li></ul><ul><li>Erik “Happi” Johansson </li></ul><ul><li>Mikael Pettersson </li></ul><ul><li>Richard Carlsson </li></ul><ul><li>Kostis Sagonas </li></ul><ul><li>have been having fun developing and maintaining the HiPE system... </li></ul>
  5. 5. HiPE: High Performance Erlang <ul><li>A “just-in-time” native code compiler for Erlang </li></ul><ul><ul><li>Allows flexible , user-controlled compilation of Erlang programs to native machine code </li></ul></ul><ul><ul><li>Fine-grained: Compilation unit is a single function </li></ul></ul><ul><li>HiPE 0.92 released as open-source in March 2000 (see also www.csd.uu.se/projects/hipe ) </li></ul><ul><ul><li>Released version was JAM-based (Erlang R4) </li></ul></ul><ul><ul><li>Available only for SPARC machines </li></ul></ul>
  6. 6. HiPE: Technical Details <ul><li>Both virtual machine code and native code can happily co-exist in the runtime system </li></ul><ul><li>HiPE optimizes calls to functions which execute in the same mode </li></ul><ul><li>Preserves tail-calls </li></ul><ul><li>The generated native code is quite efficient </li></ul><ul><ul><li>HiPE significantly outperforms all other Erlang implementations </li></ul></ul><ul><ul><li>has similar performance to e.g. Concurrent SML/NJ </li></ul></ul>
  7. 7. Old HiPE Architecture Erlang Run-Time System HiPE Compiler JAM Emulator Code area JAM Dissassembler HiPE Loader JAM Bytecode Other Data Native Code Symbolic JAM Icode RTL SPARC The HiPE system
  8. 8. Speedup of HiPE (0.92) over other Erlang implementations
  9. 9. Success of HiPE: Let’s take a quick poll... <ul><li>Who has used HiPE ? </li></ul><ul><li>My educated guess: A few… </li></ul><ul><li>Who is using HiPE instead of using Erlang/OTP ? </li></ul><ul><li>Most probable answer: None! </li></ul>
  10. 10. Part 2: Present
  11. 11. HiPE version 1.0: The current HiPE team <ul><li>At Uppsala University: </li></ul><ul><ul><li>Erik “Happi” Johansson </li></ul></ul><ul><ul><li>Mikael Pettersson </li></ul></ul><ul><ul><li>Richard Carlsson </li></ul></ul><ul><ul><li>Kostis Sagonas </li></ul></ul><ul><li>+ </li></ul><ul><ul><li>Jesper Wilhelmsson </li></ul></ul><ul><li>Recent addition from the Erlang/OTP team: </li></ul><ul><ul><li>Bjorn Gustavsson </li></ul></ul>
  12. 12. HiPE version 1.0: Main Features of Interest <ul><li>HiPE is fully and tightly integrated within Open Source Erlang/OTP Release 8 </li></ul><ul><li>Handles the full Erlang language </li></ul><ul><li>Back-ends for: </li></ul><ul><ul><li>SPARC </li></ul></ul><ul><ul><li>x86-based machines running Linux or Solaris </li></ul></ul><ul><li>Usually very reasonable compilation times </li></ul><ul><li>Acceptable sizes of object code </li></ul>
  13. 13. New HiPE Architecture Erlang Run-Time System HiPE Compiler BEAM Emulator Code area BEAM Dissassembler HiPE Loader BEAM Bytecode Other Data Native Code Symbolic BEAM Icode RTL SPARC X86 A HiPE-enabled Erlang/OTP system
  14. 14. HiPE version 1.0: Installation Guide <ul><li>1. Get Open Source Erlang/OTP R8 </li></ul><ul><li>2. If on SPARC or x86, instead of typing: </li></ul><ul><li>./configure </li></ul><ul><li>./make </li></ul><ul><li>type: </li></ul><ul><li>./configure --enable-hipe </li></ul><ul><li>./make </li></ul>
  15. 15. HiPE: Invoking the compiler (novice user) <ul><li>Instead of typing: </li></ul><ul><li>1> c(Module, Options). </li></ul><ul><li>types: </li></ul><ul><li>1> c(Module, [ native |Options]). </li></ul><ul><li>Alternatively, instead of typing: </li></ul><ul><li>erlc … File </li></ul><ul><li>types: </li></ul><ul><li>erlc +native … File </li></ul>
  16. 16. HiPE: Invoking the compiler (seasoned user) <ul><li>Instead of typing: </li></ul><ul><li>1> c(Module, Options). </li></ul><ul><li>types: </li></ul><ul><li>1> c(Module, [ native,{hipe,[’O3’,...]} |Options]). </li></ul><ul><li>Learns about the full set of HiPE compiler options by typing: </li></ul><ul><li>1> hipe:help(). </li></ul>
  17. 17. HiPE: Invoking the compiler (expert user) <ul><li>Selectively and dynamically compiles individual Erlang functions using: </li></ul><ul><li>1> c(M). </li></ul><ul><li>… </li></ul><ul><li>42> hipe:c({M,F,A}, HiPE_Opts). </li></ul><ul><li>Reports bugs to: [email_address] </li></ul>
  18. 18. HiPE: Invoking the compiler (HiPE hacker) <ul><li>Sends bug fixes and compiler improvements to: [email_address] </li></ul>
  19. 19. HiPE version 1.0: Currently known limitations <ul><li>Native code will not be unloaded once loaded into the system (slight memory leak) </li></ul><ul><li>Tracing and debugging support is non-existent </li></ul><ul><ul><li>Hint: Use HiPE once your application is debugged! </li></ul></ul><ul><li>Floating point arithmetic slower than in BEAM </li></ul><ul><li>Exception information often slightly differs between BEAM and HiPE </li></ul><ul><ul><ul><li>in particular, no tracelist is provided </li></ul></ul></ul><ul><li>Fixed size (i.e., non-resizable) constant pool </li></ul>
  20. 20. HiPE version 1.0: Performance Expectations
  21. 21. HiPE version 1.0: Useful Hints <ul><li>To get the most out of HiPE: </li></ul><ul><li>Compile all time-critical parts of your Erlang application into native code </li></ul><ul><ul><li>Separate hot from cold code (perhaps by placing them into different modules) </li></ul></ul><ul><li>Avoid easily avoidable mode-switches </li></ul>
  22. 22. Part 3: Near Future
  23. 23. HiPE: Current Work <ul><li>Optimization of inter-process communication and efficient memory management for concurrent processes </li></ul><ul><li>Formal specification of the Core Erlang language and its full integration within HiPE and Erlang/OTP </li></ul><ul><li>New inliner for the BEAM compiler </li></ul><ul><li>Experimental extensions of the Erlang language </li></ul>
  24. 24. Alternative Memory Architectures for Erlang <ul><li>Erlang/OTP has a process-centric view of memory management: </li></ul><ul><li>each process allocates each own memory area </li></ul>Interprocess communication is quite expensive Process 1 heap stack Process 2 heap stack Process n heap stack ... ... Global ETS Table
  25. 25. Alternative Memory Architectures for Erlang <ul><li>We (mainly Jesper Wilhelmsson ) have designed and implemented an Erlang/OTP system where: </li></ul><ul><ul><li>the heap is shared between all processes </li></ul></ul><ul><ul><li>but each process allocates its own stack </li></ul></ul>Process 1 stack Process 2 stack Process n stack ... Global ETS Table Interprocess communication does not involve copying of messages Global Heap
  26. 26. Unified Heap Architecture: Installation Guide <ul><li>1. Get Erlang/OTP R8 </li></ul><ul><li>2. Install by typing: </li></ul><ul><li>./configure --enable-unified-heap </li></ul><ul><li>./make </li></ul><ul><li>Warnings: </li></ul><ul><ul><li>Highly experimental at this point! </li></ul></ul><ul><ul><li>Does not work with HiPE </li></ul></ul><ul><li>Request: </li></ul><ul><ul><li>Send us your favourite concurrent Erlang application </li></ul></ul>
  27. 27. Core Erlang: Formal Specification and Use in OSE <ul><li>A small and relatively clean subset of Erlang </li></ul><ul><ul><li>Syntactic sugar is removed </li></ul></ul><ul><ul><li>Resembles other “core” FP languages </li></ul></ul><ul><li>An appropriate medium to: </li></ul><ul><ul><li>base the compiler’s front-end (already part of R8) </li></ul></ul><ul><ul><li>apply high-level transformations such as: </li></ul></ul><ul><ul><ul><li>inlining (currently under development) </li></ul></ul></ul><ul><ul><ul><li>deforestation (prototype; results so far inconclusive) </li></ul></ul></ul><ul><ul><li>base work of static analysis or verification </li></ul></ul><ul><li>A formal definition of Core Erlang is currently available as a tech report ( Richard Carlsson et al ) </li></ul>
  28. 28. Core Erlang Inliner: User’s Manual <ul><li>Instead of typing: </li></ul><ul><li>1> c(Module, Options). </li></ul><ul><li>type: </li></ul><ul><li>1> c(Module, [ inline |Options]). </li></ul>
  29. 29. Extensions of the Erlang language <ul><li>Parameterized Erlang modules </li></ul><ul><ul><li>Design laid out; issue is efficient implementation </li></ul></ul><ul><ul><li>Current work by Richard Carlsson & Mikael Pettersson </li></ul></ul><ul><li>User-defined parametric datatypes ( a la ML) </li></ul><ul><li>Structured module system for Erlang </li></ul>

×