Putting in all the stops: execution control for JavaScript

Samuel Baxter, Rachit Nigam, Joe Gibbs Politz, Shriram Krishnamurthi, Arjun Guha · OpenReview

Abstract

Stopify is a source-to-source compiler that brings advanced execution control—including pausing, single-stepping, and infinite loop protection—to any language that compiles to JavaScript. By reifying the call stack and employing sub-language optimizations, Stopify allows Web IDEs to run long-running or non-terminating code without freezing the browser tab, while remaining competitive with hand-tuned, language-specific implementations.

The Problem: The Browser as a Hostile Host

The web has become a primary environment for learning and professional development, yet the browser remains a difficult host for many programming languages. Because JavaScript is single-threaded, a simple infinite loop in a Web IDE (like while(true){}) will freeze the entire browser tab.

To prevent this, most Web IDEs currently either "kill" programs that run too long or require compiler authors to implement complex, bug-prone stack management systems to periodically "yield" control back to the browser. These manual solutions are difficult to engineer, hard to reuse across different languages, and often result in poor performance. Stopify addresses the need for a general-purpose tool that adds execution control to any JavaScript-targeting compiler without forcing a total rewrite of the compiler's backend.

Methods: JS-to-JS Transformation

Stopify functions as a secondary compilation step: it takes the JavaScript output of an existing compiler and transforms it into "instrumented" JavaScript. It employs several key strategies:

  1. First-Class Continuations: Stopify reifies the call stack, transforming code so that it can capture its current state, pause execution to let the browser process UI events, and then resume exactly where it left off.
  2. Implementation Strategies: The system supports multiple ways to handle pauses, including Checked-return (checking flags after calls), Exceptional (using exceptions to unwind the stack), and Eager (maintaining a "shadow stack" in a global array).
  3. Dynamic Yielding: Instead of yielding after a fixed number of operations, Stopify uses a sampling-based approach to estimate execution speed, ensuring the program yields roughly every 100ms to maintain UI responsiveness with minimal overhead.

Evaluation Across Languages

The authors evaluated Stopify across 10 different programming languages and 147 benchmarks, primarily drawn from the Computer Language Benchmarks Game.

Summary of compilers evaluated and the JavaScript features they utilize.

As shown in the table above, different compilers utilize different subsets of JavaScript features. Stopify leverages this through Sub-language Optimization. JavaScript is highly dynamic; even a simple x + 1 could trigger an infinite loop if x has a malicious valueOf method. Stopify allows developers to specify that their compiler uses a "well-behaved" sub-language (e.g., no implicit method calls or getters), allowing Stopify to skip expensive instrumentation on basic arithmetic.

Key Insights: The "Implicit" Tax

The biggest performance killer in JavaScript instrumentation isn't the logic itself, but the possibility of JavaScript's dynamic features being used. By identifying that most compilers ignore these features, Stopify can achieve much higher performance.

Slowdown comparison between assuming implicit method calls vs. optimizing for their absence.

As illustrated in the figure above, the performance penalty for assuming implicit method calls is significant across various benchmarks. By optimizing for sub-languages that do not use these features, Stopify drastically reduces the execution slowdown.

Key Results and Impact

  • New Capabilities: Stopify enabled the first Web IDEs with "Stop" buttons and stepping for 8 of the 10 tested languages.
  • Performance: For Python (via PyJS), the median slowdown was only 1.7x–3.8x across platforms, outperforming popular existing implementations like Skulpt.
  • Maintenance: In a case study with the Pyret language, switching to Stopify allowed developers to delete 30-60% of their complex stack-management code while fixing several long-standing execution bugs.
  • Responsiveness: The sampling-based timer successfully kept interrupt intervals close to the 100ms target, preventing "Script not responding" warnings even on low-end hardware.

Limitations and Future Work

The primary drawback of Stopify is "code bloat," increasing the size of generated JavaScript by an average of 8x. Additionally, while Stopify supports deep stacks, its performance in highly recursive programs is currently lower than hand-tuned implementations. While WebAssembly is a promising future target, the authors note it currently lacks the necessary features (like garbage collection) to implement a Stopify-like system more efficiently than JavaScript.

Summary updated

BibTeX
@inproceedings{baxter2018putting,
  author = {Samuel Baxter and Rachit Nigam and Joe Gibbs Politz and Shriram Krishnamurthi and Arjun Guha},
  title = {{Putting in all the stops: execution control for JavaScript}},
  booktitle = {PLDI},
  year = {2018},
  doi = {10.1145/3192366.3192370},
}
Figure