News for hackers. Stuff that matters.
Re:Nash – A tracing JIT compiler for Scheme [pdf] by CoffeeDregs on Saturday March 04, 2017 @02:41PM (#13792550)
Would transpiling Scheme to Javascript and then executing the resulting Javascript on NodeJS give good performance?
Re:Nash – A tracing JIT compiler for Scheme [pdf] by sedachv on Sunday March 05, 2017 @12:47AM (#13794772)
No.

NodeJS (V8) is slower than Racket in many benchmarks:

https://benchmarksgame.alioth.debian.org/u64q/measurements.p...

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

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-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.

Re:Nash – A tracing JIT compiler for Scheme [pdf] by igouy on Sunday March 05, 2017 @01:49AM (#13794910)
Let me help you with a benchmarks game URL --

http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

Re:Nash – A tracing JIT compiler for Scheme [pdf] by ufo on Saturday March 04, 2017 @04:16PM (#13792975)
I 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.

Re:Nash – A tracing JIT compiler for Scheme [pdf] by tonyg on Saturday March 04, 2017 @03:50PM (#13792867)
In principle, maybe; in practice, currently, no: Scheme requires proper tail calls, and Javascript engines as a rule do not provide them. Yet.
Re:Nash – A tracing JIT compiler for Scheme [pdf] by microcolonel on Saturday March 04, 2017 @06:18PM (#13793457)
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.

Re:Nash – A tracing JIT compiler for Scheme [pdf] by e12e on Saturday March 04, 2017 @06:15PM (#13793446)
Wouldn'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?
Re:Nash – A tracing JIT compiler for Scheme [pdf] by ufo on Saturday March 04, 2017 @07:06PM (#13793726)
Only 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.