SlideShare a Scribd company logo
1 of 31
Download to read offline
A Performant Scheme interpreter in asm.js
Noah Van Es, Jens Nicolay, Quentin Stievenart, Theo D’Hondt, Coen De Roover
6 April 2016, Symposium on Applied Computing, Pisa
noahves@vub.ac.be @noahvanes github.com/noahvanes
Context: JavaScript
‣ Language of the web
‣ “Universal virtual machine”
‣ Supports other languages:
‣ popular compilation target
‣ implementation language for interpreters
Context: JavaScript
‣ Language of the web
‣ “Universal virtual machine”
‣ Supports other languages:
‣ popular compilation target
‣ implementation language for interpreters
Problem: performance is unacceptable!
asm.js
“An extraordinarily optimizable,
low-level subset of JavaScript”
- asmjs.org
‣ Low-level subset of JavaScript
‣ very limited language
✓ no garbage collection
✓ static typing
‣ backward compatible
asm.js
“An extraordinarily optimizable,
low-level subset of JavaScript”
- asmjs.org
‣ Optimizable
‣ ‘use asm’ annotation
‣ static typing, unboxed values, …
‣ AOT-compilation
asm.js
“An extraordinarily optimizable,
low-level subset of JavaScript”
- asmjs.org
asm.js: Example
asm.js: Example
type annotations
asm.js: Example
global heap
byte addressing
Compiling from C to asm.js
‣ Used as a compilation target
‣ Emscripten toolchain
C program LLVM IR asm.js
Compiling from C to asm.js
‣ Used as a compilation target
‣ Emscripten toolchain
‣ Portable IR
‣ can be further compiled AOT …
‣ … or executed directly as JS
C program LLVM IR asm.js
Integrating asm.js by hand
‣ Integrate handwritten asm.js into existing application
‣ Key questions:
‣ is asm.js human-writable?
‣ can existing interpreters migrate to asm.js?
‣ balance between development effort and
performance?
SLIP: Simple Language Implementation Platform
‣ Scheme-like language
‣ Omits non-idiomatic features
‣ http://soft.vub.ac.be/~tjdhondt/PLE
SLIP: Simple Language Implementation Platform
‣ Scheme-like language
‣ Omits non-idiomatic features
‣ http://soft.vub.ac.be/~tjdhondt/PLE
SLIP: Base implementations
‣ Reference C implementation: ~6000 LOC
‣ Plain JS implementation: ~4000 LOC
‣ Design characteristics:
✓ continuation-passing style
✓ register-machine architecture
✓ low-level memory model
✓ garbage collection
✓ trampoline
✓ unified abstract grammar
Integrating asm.js
‣ Refactor critical modules to asm.js
MEMORY MANAGEMENT
ABSTRACT GRAMMAR
COMPILER
EVALUATOR
NATIVES
PRINTERPARSER
POOL
REPL
plain JS asm.js
Integrating asm.js
‣ Refactor critical modules to asm.js
MEMORY MANAGEMENT
ABSTRACT GRAMMAR
COMPILER
EVALUATOR
NATIVES
PRINTERPARSER
POOL
REPL
plain JS asm.js
Integrating asm.js
‣ Refactor critical modules to asm.js
MEMORY MANAGEMENT
ABSTRACT GRAMMAR
COMPILER
EVALUATOR
NATIVES
PRINTERPARSER
POOL
REPL
plain JS asm.js
Integrating asm.js
‣ Refactor critical modules to asm.js
MEMORY MANAGEMENT
ABSTRACT GRAMMAR
COMPILER
EVALUATOR
NATIVES
PRINTERPARSER
POOL
REPL
plain JS asm.js
Integrating asm.js
‣ Iterative integration process
‣ Milestones
plain JS asm.js
100%
24%
76%
7%
93% 81%
19%
asm0 asm1 asm2 asm3
Development effort
‣ Challenges in writing asm.js by hand
‣ limited type system
‣ explicit typecasts
‣ manual memory management
‣ poor abstraction mechanisms
‣ interface between JS and asm.js
Development effort
‣ Challenges in writing asm.js by hand
‣ limited type system
‣ explicit typecasts
‣ manual memory management
‣ poor abstraction mechanisms
‣ interface between JS and asm.js
Macros to the rescue
‣ Macros to facilitate writing asm.js by hand
‣ Using the sweet.js macro expander
‣ Macros help to improve:
‣ readability
‣ maintainability
‣ performance
Macros use cases
‣ Auto-generate function table, trampoline, …
Macros use cases
‣ Auto-generate function table, trampoline, …
Macros use cases
‣ Auto-generate function table, trampoline, …
Performance comparison with JavaScript
‣ Too much overhead in first iterations
‣ asm3: ~80% faster than original JS implementation
speedup
asm0 asm1 asm2 asm3
0
1
2
3
4
5
Performance comparison with C
milliseconds
0
2000
4000
6000
8000
tower-fib nqueens qsort hanoi tak cpstak ctak destruct array1 primes
asm4 native C Emscripten
Performance comparison with C
‣ asm4 is ~19% slower than native C
‣ asm4 is ~46% faster than Emscripten
nqueens
qsort
hanoi
tak
cpstak
ctak
destruct
array1
0,0
0,2
0,4
0,6
0,8
1,0
1,2
1,4
1,6
1,8
2,0
native slip.js (asm4) compiled
asm0 asm1 asm2 asm3
slowdown
native C asm4 Emscripten
Try it yourself!
‣ http://noahvanes.github.io/slip.js
Conclusion
‣ Integrated asm.js into interpreter
‣ Development effort: considerable
‣ more components had to be ported
‣ maintainability & readability improved by macros
‣ Performance: huge improvements
‣ close to native speed on the web!
noahves@vub.ac.be
github.com/noahvanes

More Related Content

What's hot

JavaScript: Past, Present, Future
JavaScript: Past, Present, FutureJavaScript: Past, Present, Future
JavaScript: Past, Present, FutureJungryul Choi
 
Using type script to build better apps
Using type script to build better appsUsing type script to build better apps
Using type script to build better appsColdFusionConference
 
Introduction to mean stack
Introduction to mean stackIntroduction to mean stack
Introduction to mean stackPraveen Gubbala
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptEric Normand
 
Web performance
Web performanceWeb performance
Web performanceLusan Das
 
Ember Overview in 5 Minutes
Ember Overview in 5 MinutesEmber Overview in 5 Minutes
Ember Overview in 5 MinutesJay Phelps
 
Introducing React to GraysOnline
Introducing React to GraysOnlineIntroducing React to GraysOnline
Introducing React to GraysOnlineJoseph Ni
 
Node.JS| Coffeescript Presentation
Node.JS| Coffeescript PresentationNode.JS| Coffeescript Presentation
Node.JS| Coffeescript PresentationSam Frons
 
Host, deploy & scale Blazor Server Apps
Host, deploy & scale Blazor Server AppsHost, deploy & scale Blazor Server Apps
Host, deploy & scale Blazor Server AppsJose Javier Columbie
 
Starting a new ruby on rails development
Starting a new ruby on rails developmentStarting a new ruby on rails development
Starting a new ruby on rails developmentNicolas Alpi
 

What's hot (18)

JavaScript: Past, Present, Future
JavaScript: Past, Present, FutureJavaScript: Past, Present, Future
JavaScript: Past, Present, Future
 
Using type script to build better apps
Using type script to build better appsUsing type script to build better apps
Using type script to build better apps
 
Introduction to mean stack
Introduction to mean stackIntroduction to mean stack
Introduction to mean stack
 
MEAN stack
MEAN stackMEAN stack
MEAN stack
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScript
 
Web performance
Web performanceWeb performance
Web performance
 
Mean PPT
Mean PPTMean PPT
Mean PPT
 
Rubyhosting
RubyhostingRubyhosting
Rubyhosting
 
Ember Overview in 5 Minutes
Ember Overview in 5 MinutesEmber Overview in 5 Minutes
Ember Overview in 5 Minutes
 
Introducing React to GraysOnline
Introducing React to GraysOnlineIntroducing React to GraysOnline
Introducing React to GraysOnline
 
Foolangjs
FoolangjsFoolangjs
Foolangjs
 
Node.JS| Coffeescript Presentation
Node.JS| Coffeescript PresentationNode.JS| Coffeescript Presentation
Node.JS| Coffeescript Presentation
 
Power Training DevDays 2009
Power Training DevDays 2009Power Training DevDays 2009
Power Training DevDays 2009
 
STATAMIC
STATAMICSTATAMIC
STATAMIC
 
Ajaxworld07
Ajaxworld07Ajaxworld07
Ajaxworld07
 
Host, deploy & scale Blazor Server Apps
Host, deploy & scale Blazor Server AppsHost, deploy & scale Blazor Server Apps
Host, deploy & scale Blazor Server Apps
 
Mean stack
Mean stackMean stack
Mean stack
 
Starting a new ruby on rails development
Starting a new ruby on rails developmentStarting a new ruby on rails development
Starting a new ruby on rails development
 

Similar to A Performant Scheme Interpreter in asm.js

JS Fest 2018. Александр Скачков. WebAssembly vs JavaScript
JS Fest 2018. Александр Скачков. WebAssembly vs JavaScriptJS Fest 2018. Александр Скачков. WebAssembly vs JavaScript
JS Fest 2018. Александр Скачков. WebAssembly vs JavaScriptJSFestUA
 
An Introduction to WebAssembly
An Introduction to WebAssemblyAn Introduction to WebAssembly
An Introduction to WebAssemblyDaniel Budden
 
JSCS - How to Style your JavaScript Code
JSCS - How to Style your JavaScript CodeJSCS - How to Style your JavaScript Code
JSCS - How to Style your JavaScript CodeArvind Bhardwaj
 
WebAssembly: A New World of Native Exploits on the Browser
WebAssembly: A New World of Native Exploits on the BrowserWebAssembly: A New World of Native Exploits on the Browser
WebAssembly: A New World of Native Exploits on the BrowserPriyanka Aash
 
WebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationWebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationBrad Beiermann
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascriptrajivmordani
 
WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?Brainhub
 
Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?
Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?
Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?OdessaJS Conf
 
WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?Alexandr Skachkov
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesSimon Willison
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?Balajihope
 
Java Script recruiting
Java Script recruitingJava Script recruiting
Java Script recruitingIhor Odynets
 
Aws architecture problems while being fancy
Aws architecture problems while being fancyAws architecture problems while being fancy
Aws architecture problems while being fancyGoran Kopevski
 
LiveCycle Scripting & Validations
LiveCycle Scripting & ValidationsLiveCycle Scripting & Validations
LiveCycle Scripting & Validationsxrum
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspmJesse Warden
 

Similar to A Performant Scheme Interpreter in asm.js (20)

JS Fest 2018. Александр Скачков. WebAssembly vs JavaScript
JS Fest 2018. Александр Скачков. WebAssembly vs JavaScriptJS Fest 2018. Александр Скачков. WebAssembly vs JavaScript
JS Fest 2018. Александр Скачков. WebAssembly vs JavaScript
 
WebAssemlby vs JavaScript
WebAssemlby vs JavaScriptWebAssemlby vs JavaScript
WebAssemlby vs JavaScript
 
An Introduction to WebAssembly
An Introduction to WebAssemblyAn Introduction to WebAssembly
An Introduction to WebAssembly
 
Lightning fast sass
Lightning fast sassLightning fast sass
Lightning fast sass
 
JSCS - How to Style your JavaScript Code
JSCS - How to Style your JavaScript CodeJSCS - How to Style your JavaScript Code
JSCS - How to Style your JavaScript Code
 
WebAssembly: A New World of Native Exploits on the Browser
WebAssembly: A New World of Native Exploits on the BrowserWebAssembly: A New World of Native Exploits on the Browser
WebAssembly: A New World of Native Exploits on the Browser
 
WebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationWebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction Presentation
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
 
WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?
 
Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?
Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?
Oleksandr Skachkov - WebAssembly vs JavaScript: What is faster?
 
WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?WebAssembly vs JavaScript: What is faster?
WebAssembly vs JavaScript: What is faster?
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
 
Into to Webassmbly
Into to WebassmblyInto to Webassmbly
Into to Webassmbly
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
Java Script recruiting
Java Script recruitingJava Script recruiting
Java Script recruiting
 
Wasm intro
Wasm introWasm intro
Wasm intro
 
DEVCON1 - BooJs
DEVCON1 - BooJsDEVCON1 - BooJs
DEVCON1 - BooJs
 
Aws architecture problems while being fancy
Aws architecture problems while being fancyAws architecture problems while being fancy
Aws architecture problems while being fancy
 
LiveCycle Scripting & Validations
LiveCycle Scripting & ValidationsLiveCycle Scripting & Validations
LiveCycle Scripting & Validations
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
 

Recently uploaded

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 

Recently uploaded (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 

A Performant Scheme Interpreter in asm.js

  • 1. A Performant Scheme interpreter in asm.js Noah Van Es, Jens Nicolay, Quentin Stievenart, Theo D’Hondt, Coen De Roover 6 April 2016, Symposium on Applied Computing, Pisa noahves@vub.ac.be @noahvanes github.com/noahvanes
  • 2. Context: JavaScript ‣ Language of the web ‣ “Universal virtual machine” ‣ Supports other languages: ‣ popular compilation target ‣ implementation language for interpreters
  • 3. Context: JavaScript ‣ Language of the web ‣ “Universal virtual machine” ‣ Supports other languages: ‣ popular compilation target ‣ implementation language for interpreters Problem: performance is unacceptable!
  • 4. asm.js “An extraordinarily optimizable, low-level subset of JavaScript” - asmjs.org
  • 5. ‣ Low-level subset of JavaScript ‣ very limited language ✓ no garbage collection ✓ static typing ‣ backward compatible asm.js “An extraordinarily optimizable, low-level subset of JavaScript” - asmjs.org
  • 6. ‣ Optimizable ‣ ‘use asm’ annotation ‣ static typing, unboxed values, … ‣ AOT-compilation asm.js “An extraordinarily optimizable, low-level subset of JavaScript” - asmjs.org
  • 10. Compiling from C to asm.js ‣ Used as a compilation target ‣ Emscripten toolchain C program LLVM IR asm.js
  • 11. Compiling from C to asm.js ‣ Used as a compilation target ‣ Emscripten toolchain ‣ Portable IR ‣ can be further compiled AOT … ‣ … or executed directly as JS C program LLVM IR asm.js
  • 12. Integrating asm.js by hand ‣ Integrate handwritten asm.js into existing application ‣ Key questions: ‣ is asm.js human-writable? ‣ can existing interpreters migrate to asm.js? ‣ balance between development effort and performance?
  • 13. SLIP: Simple Language Implementation Platform ‣ Scheme-like language ‣ Omits non-idiomatic features ‣ http://soft.vub.ac.be/~tjdhondt/PLE
  • 14. SLIP: Simple Language Implementation Platform ‣ Scheme-like language ‣ Omits non-idiomatic features ‣ http://soft.vub.ac.be/~tjdhondt/PLE
  • 15. SLIP: Base implementations ‣ Reference C implementation: ~6000 LOC ‣ Plain JS implementation: ~4000 LOC ‣ Design characteristics: ✓ continuation-passing style ✓ register-machine architecture ✓ low-level memory model ✓ garbage collection ✓ trampoline ✓ unified abstract grammar
  • 16. Integrating asm.js ‣ Refactor critical modules to asm.js MEMORY MANAGEMENT ABSTRACT GRAMMAR COMPILER EVALUATOR NATIVES PRINTERPARSER POOL REPL plain JS asm.js
  • 17. Integrating asm.js ‣ Refactor critical modules to asm.js MEMORY MANAGEMENT ABSTRACT GRAMMAR COMPILER EVALUATOR NATIVES PRINTERPARSER POOL REPL plain JS asm.js
  • 18. Integrating asm.js ‣ Refactor critical modules to asm.js MEMORY MANAGEMENT ABSTRACT GRAMMAR COMPILER EVALUATOR NATIVES PRINTERPARSER POOL REPL plain JS asm.js
  • 19. Integrating asm.js ‣ Refactor critical modules to asm.js MEMORY MANAGEMENT ABSTRACT GRAMMAR COMPILER EVALUATOR NATIVES PRINTERPARSER POOL REPL plain JS asm.js
  • 20. Integrating asm.js ‣ Iterative integration process ‣ Milestones plain JS asm.js 100% 24% 76% 7% 93% 81% 19% asm0 asm1 asm2 asm3
  • 21. Development effort ‣ Challenges in writing asm.js by hand ‣ limited type system ‣ explicit typecasts ‣ manual memory management ‣ poor abstraction mechanisms ‣ interface between JS and asm.js
  • 22. Development effort ‣ Challenges in writing asm.js by hand ‣ limited type system ‣ explicit typecasts ‣ manual memory management ‣ poor abstraction mechanisms ‣ interface between JS and asm.js
  • 23. Macros to the rescue ‣ Macros to facilitate writing asm.js by hand ‣ Using the sweet.js macro expander ‣ Macros help to improve: ‣ readability ‣ maintainability ‣ performance
  • 24. Macros use cases ‣ Auto-generate function table, trampoline, …
  • 25. Macros use cases ‣ Auto-generate function table, trampoline, …
  • 26. Macros use cases ‣ Auto-generate function table, trampoline, …
  • 27. Performance comparison with JavaScript ‣ Too much overhead in first iterations ‣ asm3: ~80% faster than original JS implementation speedup asm0 asm1 asm2 asm3 0 1 2 3 4 5
  • 28. Performance comparison with C milliseconds 0 2000 4000 6000 8000 tower-fib nqueens qsort hanoi tak cpstak ctak destruct array1 primes asm4 native C Emscripten
  • 29. Performance comparison with C ‣ asm4 is ~19% slower than native C ‣ asm4 is ~46% faster than Emscripten nqueens qsort hanoi tak cpstak ctak destruct array1 0,0 0,2 0,4 0,6 0,8 1,0 1,2 1,4 1,6 1,8 2,0 native slip.js (asm4) compiled asm0 asm1 asm2 asm3 slowdown native C asm4 Emscripten
  • 30. Try it yourself! ‣ http://noahvanes.github.io/slip.js
  • 31. Conclusion ‣ Integrated asm.js into interpreter ‣ Development effort: considerable ‣ more components had to be ported ‣ maintainability & readability improved by macros ‣ Performance: huge improvements ‣ close to native speed on the web! noahves@vub.ac.be github.com/noahvanes