3 ms·
Would transpiling Scheme to Javascript and then executing the resulting Javascript on NodeJS give good performance?
by CoffeeDregs 10y ago
Would transpiling Scheme to Javascript and then executing the resulting Javascript on NodeJS give good performance?
- tonyg 10y agoIn principle, maybe; in practice, currently, no: Scheme requires proper tail calls, and Javascript engines as a rule do not provide them. Yet.
- e12e 10y agoWouldn't any scheme runtime/compiler need to handle that, though? In other words, wouldn't a transform to a loop (on the js side) be one possible approach?
- ufo 10y agoOnly if you know at compilation time what function(s) you will be calling in a tail recursive manner. If the function you call comes from a parameter or variable (for example, in continuation passing style code) then there is no straightforward way to compile it into a loop.
- microcolonel 10y agohttp://kangax.github.io/compat-table/es6/ http://kangax.github.io/compat-table/es6/ < The most popular version of the most popular javascript engine supports tail call optimization. That said, it would still probably be worth doing the optimization in the transpiler, to avoid having the JS compiler have to work out if your program runs into any JS pitfalls.
- ufo 10y agoI wouldn't be very optimistic. How do you plan on transpiling Scheme to Javascript? The easiest way to transpile would be to write a Javascript interpreter for Scheme, but that would completely confuse the Javascript JIT compiler, since all it would see is one big hot loop with very branchy code inside it. That said, Pycket (which is mentioned in the paper) takes exactly this approach. They take advantage of PyPy's meta-JIT framework, which was designed exactly for this sort of thing. The other way would be to try to transpile Scheme directly into Javascript. But now you face the problem that there is a big mismatch between the two languages. The datatypes aren't the same, Javascript doesn't have guaranteed tail recursion, and so on. Just writing the transpiler will be a lot of work and even if you succeed, the end result is not going to look like idiomatic Javascript, so there is a good chance that the Javascript JIT won't do a good job at optimizing it.
- sedachv 10y agoNo. NodeJS (V8) is slower than Racket in many benchmarks: https://benchmarksgame.alioth.debian.org/u64q/measurements.php?lang=node https://benchmarksgame.alioth.debian.org/u64q/measurements.p... https://benchmarksgame.alioth.debian.org/u64q/measurements.php?lang=racket https://benchmarksgame.alioth.debian.org/u64q/measurements.p... Note that Racket is not even in the top 5 for most Scheme compiler benchmarks: https://ecraven.github.io/r7rs-benchmarks/benchmark.html https://ecraven.github.io/r7rs-benchmarks/benchmark.html There are a bunch of Scheme implementations in JS, none of them are benchmarked in the previous link: https://github.com/jashkenas/coffeescript/wiki/List-of-languages-that-compile-to-JS#scheme-like https://github.com/jashkenas/coffeescript/wiki/List-of-langu... JavaScript is a really shitty language to target because it has very few performant control structures and terrible data types (you need ints and good arrays). Scheme also has first-class continuations, which cannot be implemented efficiently in JavaScript. Even if you leave out continuations IMO it is impossible to make a performant transpiler for most languages that targets JavaScript.
- igouy 10y agoLet me help you with a benchmarks game URL -- http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=node&lang2=racket http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...