JavaScript in JavaScript (js.js): smaller, faster, and with demos
sns.cs.princeton.edu
sns.cs.princeton.edu
[1] http://en.wikipedia.org/wiki/Narcissus_%28JavaScript_engine%...
The very awesome twitter demo on the js.js site is one example of something you could no way do with narcissus except as a proof of concept in FF.
PS: Some "Python" in above sentences might actually be rpython. But as it is subset of python it probably doesn't matter.
This is far overreaching and as such very wrong. Also, "x language is faster than y language" is a meaningless comparison. Faster at what? In what cases? Pypy does some things faster than Cpython in some cases.
>PS: Some "Python" in above sentences might actually be rpython. But as it is subset of python it probably doesn't matter.
I don't know for sure that this is wrong, but it sure seems to be.
As for the PS; RPython is statically typed Python (perhaps some other extra restrictions apply). Not type-annotated or anything, just pure python written in a certain way. So it is a subset. As for what "Python" should have been "RPython", it was the first one. The pypy interpreter is written in RPython. But my statement was still correct because RPython is Python.
IIRC it was due to better cache locality.
As an aside, Tcl has had the ability to create sandboxed sub-interpreters whose calls can be intercepted for a long time now. http://www.tcl.tk/man/tcl8.5/TclCmd/interp.htm
Note that this is different from Python's Process module. There is no new process or even thread. Everything happens within one process.
Native result for iteration NaN: 1
js.js result for iteration NaN: 0
Native result for iteration 46: 1836311903
js.js result for iteration 46: 1836311903
Native result for iteration 47: 2971215073
js.js result for iteration 47: -1675624448
It allows you to run potentially malicious js code on the server.
If they just do it for the hack value, that's totally fine for me.
However if you really want speed I wonder if you could bridge access to certain useful functions by delegating access to, for example, sandboxedAnimate = function (sel, attr, duration, easing) {} in a closure. If you want to allow plugins on your site for example, 200X for basic stuff and full speed for jquery animations, etc would be more than enough 99.9% of the time.
Also if you use CSS animations where there would be zero slowdown. So make that plenty fast 99.99% of the time.
1. The js.js API is currently very low-level, which makes it verbose and difficult to use. There's a lot of room for improvement.
2. The twitter script was actually chosen because it's complex. It has a ton of boilerplate code that you'd probably be surprised is in there.
3. A lot of the code written could be generalized into a generic virtual DOM interface library that is not specific to this twitter script. Things like screen.width and screen.height are common properties that would be accessed by many different scripts and so could be generalized.
var env = {local1: function (){}, local2: "blah"};
js = new JSJS(env);
js.eval("console.log('I am evil!'); local1();");Now there is a way to allow users to actually supply you with html markup and not have to do anything special filtering-wise on your backend.
Would love to be enlightened though. It does sound interesting.
Also, as they say they just got this working. It seems reasonable to assume that with enough programming mojo, the slowdown could be something closer to 10X or even 5X.
Or, you know, use dx and transcompile it to Dalvik bytecode.
[0]: Unfortunately, JRuby gives gcj/gij a hard time - gcj hits an internal error and gij makes it report that gij is unsupported. :(
I hear they're out of fashion..
Edit: posted this 4 minutes ago and already got 4 downvotes. Some of you guys really care about this don't you?
Carry on, not like I was gonna save up karma for a free plane ticket or something :P