Putting in All the Stops: Execution Control for Javascript

Putting in All the Stops: Execution Control for Javascript

Putting in All the Stops: Execution Control for JavaScript Samuel Baxter Rachit Nigam Joe Gibbs Politz University of Massachusetts Amherst University of Massachusetts Amherst University of California San Diego USA USA USA Shriram Krishnamurthi Arjun Guha Brown University University of Massachusetts Amherst USA USA Abstract ACM Reference Format: Scores of compilers produce JavaScript, enabling program- Samuel Baxter, Rachit Nigam, Joe Gibbs Politz, Shriram Krish- mers to use many languages on the Web, reuse existing namurthi, and Arjun Guha. 2018. Putting in All the Stops: Exe- cution Control for JavaScript. In Proceedings of 39th ACM SIG- code, and even use Web IDEs. Unfortunately, most compilers PLAN Conference on Programming Language Design and Imple- inherit the browser’s compromised execution model, so long- mentation (PLDI’18). ACM, New York, NY, USA, 16 pages. htps: running programs freeze the browser tab, ininite loops crash //doi.org/10.1145/3192366.3192370 IDEs, and so on. The few compilers that avoid these problems sufer poor performance and are diicult to engineer. This paper presents Stopify, a source-to-source compiler 1 Programming On the Web that extends JavaScript with debugging abstractions and Scores of programming languages now compile to JavaScript blocking operations, and easily integrates with existing com- and run on the Web [23] and there are several Web IDEs pilers. We apply Stopify to ten programming languages and in widespread use [4, 6ś8, 48, 57, 69, 74, 78, 83]. This grow- develop a Web IDE that supports stopping, single-stepping, ing audience for Web IDEs and languages that run in the breakpointing, and long-running computations. For nine lan- browser includes both professionals and students. Unfortu- guages, Stopify requires no or trivial compiler changes. For nately, JavaScript and the Web platform lack the abstractions eight, our IDE is the irst that provides these features. Two of necessary to build IDEs and serve as a complete compilation our subject languages have compilers with similar features. target for high-level languages. As a result, most compilers Stopify’s performance is competitive with these compilers that produce JavaScript compromise on semantics and most and it makes them dramatically simpler. Web IDEs compromise on basic debugging and usability fea- Stopify’s abstractions rely on irst-class continuations, tures. Furthermore, as we explain in ğ7, new technologies which it provides by compiling JavaScript to JavaScript. We such as WebAssembly and Web Workers do not address most also identify sub-languages of JavaScript that compilers im- of the problems that we address. Instead, our work may be plicitly use, and exploit these to improve performance. Fi- viewed as presenting additional challenges to the creators of nally, Stopify needs to repeatedly interrupt and resume pro- those technologies. gram execution. We use a sampling-based technique to esti- mate program speed that outperforms other systems. Limitations in Web IDEs The key problem facing a Web IDE is that JavaScript has a single-threaded execution envi- CCS Concepts · Software and its engineering → Com- ronment. An IDE that wants to provide a łstopž button to pilers; halt runaway computation faces a nontrivial problem, be- cause the callback for that button gets queued for execution Keywords JavaScript, continuations, IDEs behind the running codeÐwhich is not going to terminate. Related to this, to make pages responsive, the browser threat- Permission to make digital or hard copies of all or part of this work for ens to interrupt computations that run longer than a few personal or classroom use is granted without fee provided that copies are not made or distributed for proit or commercial advantage and that copies bear seconds. This means long-running computations need to be this notice and the full citation on the irst page. Copyrights for components broken up into short events. In turn, because computations of this work owned by others than ACM must be honored. Abstracting with cannot run for very long, JavaScript engines in browsers credit is permitted. To copy otherwise, or republish, to post on servers or to tend to provide very shallow stacks, which is problematic redistribute to lists, requires prior speciic permission and/or a fee. Request for functional programs that rely on recursion. permissions from [email protected]. These limitations are not at all hypothetical. For example, PLDI’18, June 18ś22, 2018, Philadelphia, PA, USA © 2018 Association for Computing Machinery. Codecademy has a Web IDE for JavaScript and for Python. ACM ISBN 978-1-4503-5698-5/18/06...$15.00 In response to several message board requests, Codecademy htps://doi.org/10.1145/3192366.3192370 has a help article that explicitly addresses ininite loops that PLDI’18, June 18ś22, 2018, Philadelphia, PA, USA S. Baxter, R. Nigam, J.G. Politz, S. Krishnamurthi, and A. Guha freeze the browser [81]: they suggest refreshing the page, 1 type Opts = { 2 cont: 'checked' | 'exceptional' | 'eager', // continuation representation which loses browser state and recent changes. Other systems, 3 ctor: 'direct' | 'wrapped', // constructor representation 4 timer: 'exact' | 'countdown' | 'approx', // time estimator such as CodeSchool, Khan Academy, and Python Tutor [18], 5 yieldInterval: number, // yield interval address this problem by killing all programs that run for more 6 stacks: 'normal' | 'deep', // deep stacks 7 implicits: true | false | '+', // implicit conversions than a few seconds. These problems also alict research- 8 args: true | false | 'mixed' | 'varargs', // arity-mismatch behavior 9 getters: true | false, // support getters driven programming languages, such as Elm [11] and Lively 10 eval: true | false // apply stopify to eval'd code 11 } Kernel [48], which crash when given an ininite loop. ğ7 12 discusses all these systems in more detail. 13 type AsyncRun = { 14 run: (onDone: () => void) => void, Some Web IDEs run user code on servers. However, this 15 pause: (onPause: () => void) => void, 16 resume: () => void approach has its own limitations. The provider has to pay 17 } for potentially unbounded server time, servers must run 18 19 function stopify(source: string, opts: Opts): AsyncRun; untrusted code, and state (e.g., time) may relect the server and not the client. Moreover, users have to trust servers, Figure 1. A portion of the stopify api. cannot work oline, and cannot leverage the browser’s DOM environment. In this paper, we focus on IDEs that run user code in the browser. Our Approach Our goal is to enhance JavaScript to make Preliminary Solutions There are a handful of robust pro- it a suitable target for Web IDEs and, more broadly, to run a gramming language implementations for the Web: GopherJS variety of languages atop JavaScript without compromising (Go) [17], Pyret [57], Skulpt (Python) [68], Doppio (JVM) [77], their semantics and programming styles. Our system, Stopify, GambitJS (Scheme) [71], and Whalesong (Racket) [83]. They is a compiler from JavaScript to JavaScript. Given a naïve use sophisticated compilers and runtime systems to support compiler from language L to JavaScriptÐcall it LJSÐwe can some subset of long-running computations, shared-memory compose it with Stopify. Stopify prepares the code for Web concurrency, blocking I/O, proper tail calls, debugging, and execution while leaving LJS mostly or entirely unchanged. other features that are diicult to implement in the browser. Stopify relies on four key ideas. The irst is to reify contin- However, these systems have several shortcomings. uations with a family of implementation strategies (ğ3). The First, these systems are diicult to build and maintain second is to identify reasonable sub-languages of JavaScriptÐ because they must efectively implement expressive con- as targeted by compilersÐto reduce overhead and hence trol operators that JavaScript does not natively support. For improve performance (ğ4). The third is to dynamically de- example, GopherJS has had several issues in its implemen- termine the rate at which to yield control to the browser, tation of goroutines [10, 12, 13, 15, 42, 72]; Skulpt [68] has improving performance without hurting responsiveness (ğ5). had bugs in its debugger [14, 60]; and the Pyret IDE has Finally, we study how these diferent techniques vary in problems (ğ6.4), several of which remain unresolved. In fact, performance across browsers, enabling browser-speciic per- the team that built Pyret previously developed a Web IDE formance improvements (ğ6). for Scheme [84], but could not reuse the compiler from the Continuations and execution control features enable new Scheme system, because the execution control techniques capabilities for languages that compile to JavaScript. We and the language’s semantics were too tightly coupled. show several: (1) Stopify supports long running computa- Second, these systems force all programs to pay for all tions by periodically yielding control to the browser; (2) features. For example, Pyret forces all programs to pay the Stopify provides abstractions that help compilers simulate cost of debugging instrumentation, even if they are running blocking operations atop nonblocking APIs; (3) Stopify en- in production or at the command-line; GopherJS forces all ables stepping debuggers via source maps; (4) Stopify allows programs to pay the cost of goroutines, even if they don’t simulating a much deeper stack than most browsers provide; use concurrency; and Doppio forces all programs to pay and (5) Stopify can simulate tail calls on browsers that don’t the cost of threads, even if they are single-threaded. Third, implement them natively. these compilers have a single back-endÐone that is presum- We evaluate the efectiveness of Stopify in ive ways: ably already complex enoughÐfor all browsers, hence do not maximize performance on any particular browser. Finally, it 1. We evaluate Stopify on ten compilers that produce is hard for a compiler author to try a new approach, since JavaScript, nine of which require no changes, and quan- small conceptual changes can require the entire compiler tify the cost of Stopify using 147 benchmarks (ğ6.1).

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us