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