Implementing a performant scheme interpreter for the web in asm.js

This paper presents the implementation of an efficient interpreter for a Scheme-like language using manually written asm.js code. The asm.js specification defines an optimizable subset of JavaScript that has already served well as a compilation target for web applications where performance is critical. However, its usage as a human-writable language that can be integrated into existing projects to improve performance has remained largely unexplored. We therefore apply this strategy to optimize the implementation of an interpreter. We also discuss the feasibility of this approach, as writing asm.js by hand is generally not its recommended use-case. We therefore present a macro system to solve the challenges we encounter. The resulting interpreter is compared to the original C implementation and its compiled equivalent in asm.js. This way, we evaluate whether manual integration with asm.js provides the necessary performance to bring larger applications and runtimes to the web. We also refactor our implementation to assess how more JavaScript code can cohabit with asm.js code, improving maintainability of the implementation while preserving near-native performance. In the case of our interpreter, this improved maintainability enables adding more complex optimizations. We investigate the addition of function inlining, for which we validate the performance gain. A novel approach to efficient language implementation on the web is presented.Integrating asm.js in a JavaScript application can yield near-native performance.Frequently calling in and out asm.js components causes a significant overhead.Macros are proposed as a solution to write asm.js code by hand.Interoperability and optimal usage of asm.js and high-level JavaScript is discussed.

[1]  Simon L. Peyton Jones,et al.  Secrets of the Glasgow Haskell Compiler inliner , 2002, Journal of Functional Programming.

[2]  Theo D'Hondt,et al.  A performant scheme interpreter in asm.js , 2016, SAC.

[3]  Gerald J. Sussman,et al.  Structure and Interpretation of Computer Programs, Second Edition , 1996 .

[4]  Brian Hackett,et al.  Fast and precise hybrid type inference for JavaScript , 2012, PLDI '12.

[5]  Manuel Serrano Inline Expansion: When and How? , 1997, PLILP.

[6]  Christian Queinnec Lisp in small pieces , 1994 .

[7]  Alon Zakai Emscripten: an LLVM-to-JavaScript compiler , 2011, OOPSLA Companion.

[8]  Marc Feeley,et al.  Speculative Inlining of Predefined Procedures in an R5RS Scheme to C Compiler , 2008, IFL.

[9]  Carl Friedrich Bolz,et al.  Tracing the meta-level: PyPy's tracing JIT compiler , 2009, ICOOOLPS@ECOOP.

[10]  Jan Martin Jansen,et al.  Implementing a non-strict purely functional language in JavaScript , 2011 .

[11]  Philip J. Fleming,et al.  How not to lie with statistics: the correct way to summarize benchmark results , 1986, CACM.

[12]  de Ng Dick Bruijn Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem , 1972 .

[13]  Gerald J. Sussman,et al.  Structure and interpretation of computer programs , 1985, Proceedings of the IEEE.

[14]  Chris Lattner,et al.  LLVM: AN INFRASTRUCTURE FOR MULTI-STAGE OPTIMIZATION , 2000 .

[15]  Mitchell Wand,et al.  Essentials of programming languages (3. ed.) , 2001 .

[16]  Mitchell Wand,et al.  Essentials of programming languages , 2008 .

[17]  Rainer Leupers,et al.  Function inlining under code size constraints for embedded processors , 1999, 1999 IEEE/ACM International Conference on Computer-Aided Design. Digest of Technical Papers (Cat. No.99CH37051).

[18]  Pieter H. Hartel,et al.  Programming languages : implementations, logics, and programs : 9th International Symposium, PLILP '97 including a special track on declarative programming languages in education, Southampton, UK, September 3-5, 1997 : proceedings , 1997 .