jsx/JSX — pull request #299 by wasabiz (2014-02-07 12:23:18+00:00)
Title: indirect threading

Changing the way to dispatch branches of transformed javascript code.

A problem the current JSX' transformer has is the output code endlessly consumes the stack. The transformer is designed to emit a number of tail-calls to realize goto-like behavior in JavaSciprt and it results in this 'stack overflow'. Usually we don't need to take care of this when compiling small generator functions but the expression transformer we intend to introduce in near future is easily broken by this. So I hack some code and implemented another dispatching method: 'indirect dispatching' (I'm not the name I call is correct or not).

This implementation compiles all statements into a huge and unreadable combination of while and switch statements. This can be seen in a sense optimized tail-call jumps by TCO.

I ran a small benchmark that calculates the 100,000 smallest primes numbers and the results are shown below. I don't know why exactly but the new indirect threading impl is slightly slower then the old one.

https://gist.github.com/wasabiz/8861526

```
$ time node prime-bench.jsx.tail-call.js
2.29s user 0.02s system 100% cpu 2.303 total
$ time node prime-bench.jsx.indirect-threading.js
2.92s user 0.02s system 100% cpu 2.933 total
```

This looks a bit bad to me and I just hesitate to merge. One option is to provide a new switch to change the output format, but I don't know it really worth doing it.