-
Notifications
You must be signed in to change notification settings - Fork 64
Understand Performance
How is the performance of the generated WebAssembly code?
WebAssembly implementations do not currently have a JIT like Java and it is expected that this will never be the case. This means the code will run ever with the same speed. This make performance test easier.
Typical an optimized code run with approximate 70% of the speed of a high jitted Java code. This vary for different code snippet and different vendors of the WebAssembly runtime.
The Java compiler create a very pure code. First the JIT compiler optimized the code. In the future JWebAssembly will have some optimizing but until you should write self optimized source code if performance is a problem. The follow 2 sample run with Java with the same speed thanks the JIT.
for( int i=0; i<list.size(); i++ ) {
//...
}
int size = list.size();
for( int i=0; i<size; i++ ) {
//...
}
With JWebAssembly the second sample run faster because there are fewer method calls.
Currently WebAssembly does not have a GC and object allocation. There is only a large linear memory. Instead to implements its own GC that need to add to every program JWebAssembly use the GC of JavaScript with a polyfill. This produce a larger JavaScript glue code but smaller *.wasm file. The calls of JavaScript code is relative slow like native calls in Java. This result is a performance of approximate 10%-20% of a Java program. The state of the future GC in WebAssemby can you see in the proposal.