Frequently Asked Questions

What is Stopify?

Scores of languages now compile to JavaScript, which allows programmers to use many languages on the Web. Unfortunately, most compilers simply inherit the browser's execution model: long-running programs freeze the browser tab, blocking operations do not work, deeply recursive programs quickly overflow the stack, infinite loops crash Web-based IDEs, and so on. Stopify is a JavaScript-to-JavaScript compiler that is designed to help compiler authors address these limitations easily and efficiently.

How does Stopify work?

There are four key pieces to Stopify.

  • First-class continuations: Stopify's abstractions rely on first-class continuations, which it provides by compiling JavaScript to JavaScript.
  • Browser-specific optimizations: There are several ways to implement continuations in JavaScript and it turns out that different approaches work best on different browsers. Stopify can give a compiler multiple backends to maximize performance.
  • Sub-languages of JavaScript: JavaScript has several unusual language features that make it very difficult to implement Stopify efficiently. Fortunately, most source languages compile to sub-languages of JavaScript that don't use all of JavaScript's features. (e.g., the image of OCaml in JavaScript is very simple sub-language of JavaScript.) We have identified several sub-languages that many compilers use and Stopify exploits them to maximize performance.
  • Time estimation: Stopify needs to periodically interrupt execution and yield control to the browser's event loop. The frequency of interruptions has to strike a balance between performance and responsiveness. Moreover, checking the system time too frequently from JavaScript also slows the program down. Stopify uses a sampling-based technique to estimate the rate at which the program executes and dynamically adjusts the interrupt rate.

How does Stopify perform?

See the question above: it depends on the source language and the sub-language of JavaScript that the source language compiler uses. We have extensive benchmarks that we can share if you're interested. But, to give an example, on Python (using PyJS), we find that the median slowdown is 1.4x. PyJS doesn't use all of JavaScript's features and we can exploit that to improve performance. Our worst slowdown is when the source language is JavaScript itself because we can't make simplifying assumptions. The median slowdown we get on the Kraken benchmark squite is 20x. These are slowdowns on a $200 ChromeBook. We also have results from the four major browsers on a desktop machine.

Do I always have to pay this slowdown?

No! Stopify is a stand-alone component that applies to the output of existing compilers. Therefore, it would be easy for an IDE to offer a fast "release mode" (without Stopify) and a slower "debug mode" (with Stopify) that users can choose between.

Why not use Web Workers?

Stopify runs programs on the main JavaScript thread, which gives you full access to the DOM, the network, etc. This is particularly important for many web-based IDEs that rely on graphics. A Web Worker would give us to ability to run a long-running computation and kill it, but would make DOM access much harder. Moreover, a Web Worker does not provide provide the rich execution control that Stopify provides, e.g., pausing, breakpointing, and deep stacks.

Why not use WebAssembly?

We think WebAssembly is awesome! However, at the moment, it is really designed to be a target for C/C++. Currently, garbage collection, threads, tail calls, and host bindings (e.g., access to the DOM) are in the feature proposal stage. Threfore, WebAssembly today does not provide enough features to prototype a Stopify-like solution. As WebAssembly evolves to support higher-level languages, web-based IDEs will want to use it. For that to happen, WebAssembly will need to support the kind of execution control that Stopify provides for JavaScript.

Can Stopify be applied to more than IDEs?

Yes! Stopify implements first-class continuations for JavaScript, so you can easily use it to build anything that first-class continuations allow. Let us know what you do with Stopify!

How can I incorporate Stopify into my compiler or IDE?

The GitHub repository has more information on how to use Stopify. If you do use Stopify, please let us know and acknowledge Stopify on your web page if possible. Stopify is developed by academics and evidence of its impact will help us continue development.

I received an unexpected compiler error or runtime error.

There are three kinds of errors that you may encounter on this demo site:

  1. Stopify uses a third-party compiler to translate the source language X to JavaScript. You may have written a program in language X that the X-to-JavaSCript compiler does not support. For example, none of the compilers support featured on this site support the file system. We have curated a suite suite of benchmarks that do work both natively and on the Web.
  2. This website uses Google Cloud Functions to run the Stopify compiler and all third-party compilers. Large source programs may not compile within the strict memory limits of Cloud Functions. Stopify will not have this issue when running on a reasonable desktop or laptop.
  3. You may have encountered a bug in Stopify. We use GitHub Issues to track bugs. Please let us know.