Mitigating JavaScript’s overhead with WebAssembly
Ylenius, Samuli (2020)
Ylenius, Samuli
2020
Ohjelmistokehityksen maisteriohjelma, FM (engl) - Master's Degree Programme in Software Development
Informaatioteknologian ja viestinnän tiedekunta - Faculty of Information Technology and Communication Sciences
This publication is copyrighted. You may download, display and print it for Your own personal use. Commercial use is prohibited.
Hyväksymispäivämäärä
2020-03-20
Julkaisun pysyvä osoite on
https://urn.fi/URN:NBN:fi:tuni-202003122682
https://urn.fi/URN:NBN:fi:tuni-202003122682
Tiivistelmä
The web and web development have evolved considerably during its short history. As a result, complex applications aren’t limited to desktop applications anymore, but many of them have found themselves in the web. While JavaScript can meet the requirements of most web applications, its performance has been deemed to be inconsistent in applications that require top performance. There have been multiple attempts to bring native speed to the web, and the most recent promising one has been the open standard, WebAssembly.
In this thesis, the target was to examine WebAssembly, its design, features, background, relationship with JavaScript, and evaluate the current status of WebAssembly, and its future. Furthermore, to evaluate the overhead differences between JavaScript and WebAssembly, a Game of Life sample application was implemented in three splits, fully in JavaScript, mix of JavaScript and WebAssembly, and fully in WebAssembly. This allowed to not only compare the performance differences between JavaScript and WebAssembly but also evaluate the performance differences between different implementation splits.
Based on the results, WebAssembly came ahead of JavaScript especially in terms of pure execution times, although, similar benefits were gained from asm.js, a predecessor to WebAssembly. However, WebAssembly outperformed asm.js in size and load times. In addition, there was minimal additional benefit from doing a WebAssembly-only implementation, as just porting bottleneck functions from JavaScript to WebAssembly had similar performance benefits. Web ja webkehitys ovat kehittyneet merkittävästi niiden lyhyen historiansa aikana. Sen seurauksena monimutkaiset sovellukset eivät enää ole rajoitettu työpöytäsovelluksiksi, vaan niitä löytyy myös webistä. Vaikka JavaScript pystyy täyttämään suurimman osan web-sovelluksien vaatimuksista, sen suorituskyky on koettu puutteelliseksi sovelluksissa, jotka vaativat huippusuorituskykyä. Vuosien aikana on ollut monta yritystä tuoda natiivisuorityskykyä webiin ja näistä uusin sekä lupaavin on avoin standardi, WebAssembly.
Tässä työssä tavoitteena on tutkia tarkemmin WebAssemblyä, sen suunnittelua, ominaisuuksia, taustaa, yhteyttä JavaScriptin kanssa, sekä WebAssemblyn nykyistä tilaa ja tulevaisuutta. Sen lisäksi, JavaScriptin ja WebAssemblyn suorituskykyä
vertaillaan toteuttamalla Life-peli kolmella eri tavalla, ensimmäinen versio täysin JavaScriptillä, toinen JavaScriptillä ja WebAssemblyllä, ja viimeiseksi täysin WebAssemblyllä. Tämä lähestymistapa mahdollisti JavaScriptin ja WebAssemblyn suorituskykyerojen vertailun lisäksi myös eri toteutustapojen arvioinnin.
Toteutettujen sovellusten perusteella huomattiin, että WebAssemblyn suorituskyky suoritusaikojen perusteella oli merkittävästi JavaScriptiä nopeampi. Vaikkakin, WebAssemblyn edeltäjällä, asm.js:lla oli samankaltaiset suorituskykytulokset kuin WebAssemblyllä. Kuitenkin, WebAssemblyn tulokset tiedostojen koissa ja latausajoissa olivat asm.js:a paremmat. Tuloksista havaittiin myös, että täys-WebAssembly toteutustapa ei tuonut merkittäviä hyötyjä suorituskykyyn JavaScript+WebAssembly toteutukseen verrattuna, jossa pullonkaula JavaScript funktioita siirrettiin WebAssemblyn puolelle.
In this thesis, the target was to examine WebAssembly, its design, features, background, relationship with JavaScript, and evaluate the current status of WebAssembly, and its future. Furthermore, to evaluate the overhead differences between JavaScript and WebAssembly, a Game of Life sample application was implemented in three splits, fully in JavaScript, mix of JavaScript and WebAssembly, and fully in WebAssembly. This allowed to not only compare the performance differences between JavaScript and WebAssembly but also evaluate the performance differences between different implementation splits.
Based on the results, WebAssembly came ahead of JavaScript especially in terms of pure execution times, although, similar benefits were gained from asm.js, a predecessor to WebAssembly. However, WebAssembly outperformed asm.js in size and load times. In addition, there was minimal additional benefit from doing a WebAssembly-only implementation, as just porting bottleneck functions from JavaScript to WebAssembly had similar performance benefits.
Tässä työssä tavoitteena on tutkia tarkemmin WebAssemblyä, sen suunnittelua, ominaisuuksia, taustaa, yhteyttä JavaScriptin kanssa, sekä WebAssemblyn nykyistä tilaa ja tulevaisuutta. Sen lisäksi, JavaScriptin ja WebAssemblyn suorituskykyä
vertaillaan toteuttamalla Life-peli kolmella eri tavalla, ensimmäinen versio täysin JavaScriptillä, toinen JavaScriptillä ja WebAssemblyllä, ja viimeiseksi täysin WebAssemblyllä. Tämä lähestymistapa mahdollisti JavaScriptin ja WebAssemblyn suorituskykyerojen vertailun lisäksi myös eri toteutustapojen arvioinnin.
Toteutettujen sovellusten perusteella huomattiin, että WebAssemblyn suorituskyky suoritusaikojen perusteella oli merkittävästi JavaScriptiä nopeampi. Vaikkakin, WebAssemblyn edeltäjällä, asm.js:lla oli samankaltaiset suorituskykytulokset kuin WebAssemblyllä. Kuitenkin, WebAssemblyn tulokset tiedostojen koissa ja latausajoissa olivat asm.js:a paremmat. Tuloksista havaittiin myös, että täys-WebAssembly toteutustapa ei tuonut merkittäviä hyötyjä suorituskykyyn JavaScript+WebAssembly toteutukseen verrattuna, jossa pullonkaula JavaScript funktioita siirrettiin WebAssemblyn puolelle.