Liftoff: a new baseline compiler for WebAssembly in V8
v8project.blogspot.com
v8project.blogspot.com
I gave a talk about it back in June. Slides: https://docs.google.com/presentation/d/1n75Mo09HmyruV5S7q0cH... video: https://youtu.be/2eISBAbT3GM?t=1h22m3s
for (let i=0; i<a.length; i++) {
a[i] = a[i]*2
}
Without lifting, every time through the loop it has to check that a is an array and (i >= 0 && i < a.length). Lifting lets the compiler move all the checks before the loop and do them once. It's nontrivial to check that the truth value of the check can't possibly change during the loop.> Without lifting, every time through the loop it has to check that a is an array and (i >= 0 && i < a.length).
It sounds like these checks are being performed once. Does that mean that instead of it checking in the loop, it's checked prior to and outside of the loop body? Otherwise, I'm not sure how the value of (i < a.length) wouldn't change as the loop is performed multiple times, as the increment expression is called after every loop.
Thanks for your help!
for (let i = 0; i < a.length; i++) {
a[i] = a[i]*2
}
Has to be converted into something that can be run onto a machine that won't cause a fatal error if the array `a` doesn't have an item at index `i` (e.g. negative index). It can be converted to the following by a naive compiler: for (let i = 0; i < a.length; i++) {
if (i > 0 && a < a.length) { // safe to access
a[i] = a[i] * 2
} else {
throw('in a safe way')
}
}
Or, to avoid repetitive checks to a.length: const temp = a.length
for (let i = 0; i < temp; i++) {
if (i > 0 && a < temp) { // safe to access
a[i] = a[i] * 2
}
}
A more advanced compiler might realise that the if statement is irrelevant, we've defined it in the loop that we'll never have a negative `i` or one above the length of the array, so we can just avoid those checks entirely and actually revert back to the original code to compile. This is not always the case: const temp = a.length
for (let i = 0; i < temp; i++) {
a[i] = a[i]*2
}
This comes up in interesting places, like why it is faster to go through an array backwards than forwards[0].[0] https://stackoverflow.com/questions/8689573/why-is-iterating...
Does anyone know of projects that ship wasm files (preferably via npm)?
I would like to try out the streaming API but I don't want to compile C++ right now
const module = await WebAssembly.compileStreaming(fetch('foo.wasm'));It's from Mozilla iirc.
Our first aim is to implement a few trivial apps without framworks completely in WASM, benchmark and move on to building the real deal.
We're currently building https://reactjs.org/docs/thinking-in-react.html in C/WASM (no Framework). Demo: http://www.write.pub/wasm-demo/hello.html
Love to see liftoff making wasm immediately executable, secure and performant (albeit small delay)
Wasm is the Java applets and flash swf of our generation