News for hackers. Stuff that matters.
Re:Node.js on mozilla spidermonkey by FooBarWidget on Thursday April 21, 2011 @05:17AM (#2469890)
Are people doing this just for fun or are there advantages in switching to Spidermonkey?
Re:Node.js on mozilla spidermonkey by ivank on Thursday April 21, 2011 @06:11AM (#2470017)
I don't know if this is their motivation for it, but SpiderMonkey implements many useful non-standard features, including generators and iterators.

JS 1.5: https://developer.mozilla.org/en/JavaScript/New_in_JavaScrip...

JS 1.6: https://developer.mozilla.org/en/JavaScript/New_in_JavaScrip...

JS 1.7: https://developer.mozilla.org/en/JavaScript/New_in_JavaScrip... <- generators, iterators, and more

JS 1.8: https://developer.mozilla.org/en/JavaScript/New_in_JavaScrip...

(As a side note, I once implemented Twisted's inlineCallbacks in JS 1.7; this worked because it had those Python-like generators. Too bad it doesn't work anywhere but SpiderMonkey.)

Re:Node.js on mozilla spidermonkey by pcwalton on Thursday April 21, 2011 @10:46AM (#2470782)
Those features are a lot of the reason for it, yes. As a cool example of what can be done with generators, check out my colleague Dave Herman's task.js library: https://github.com/dherman/taskjs

That library gives you coroutine-style I/O on top of node.js primitives, which is, as far as I can tell, the #1 feature people have been asking for all along in Node. It only works if node.js implements coroutines (which Ryan has so far refused to do) or if the language implements generators (which you get with SpiderMonkey).

Re:Node.js on mozilla spidermonkey by bnoordhuis on Thursday April 21, 2011 @05:51AM (#2469945)
V8 is a single-threaded VM and I don't see that changing any time soon, it's very much married to Chrome's per-process model. SpiderMonkey doesn't have that drawback, it supports threads just fine.

These guys have their work cut out for them if they want to support the V8 API from within SM. It's a well designed API but large and fast moving.

Still, an interesting project. I'm going to watch it, maybe submit a few patches.

Re:Node.js on mozilla spidermonkey by udp on Thursday April 21, 2011 @09:01AM (#2470434)
I had some problems with SpiderMonkey's thread safe mode. If you have your own lock system, and you lock a resource while running JS, SM might do garbage collection at any time, for which it has its own lock. This causes deadlock very quickly indeed.

I had to resort to having a pool of JS runtimes from which each thread would borrow a runtime when it wanted to execute code, and return it when it was finished. This got messy quickly when I found out that script objects can't be shared, and I needed to load an individual copy of each script for each runtime.

Furthermore, JS objects weren't able to be shared between threads even when I didn't have separate runtimes, and I needed to (this was actually the recommended approach) write them to a binary format using JS_WriteStructuredClone when one thread was finished with them, and reassemble them with JS_ReadStructuredClone on the other end.

In the end, I gave up trying to do multithreaded Javascript and went for a nice, single threaded event driven model. I don't regret it. Heck, since it's lock-free - and structured clone free - it's probably more scalable!

Re:Node.js on mozilla spidermonkey by bnoordhuis on Thursday April 21, 2011 @09:34AM (#2470534)
I hear you, threading in SM is indeed fraught with dangers.

On the off chance that you're going to revisit it, the way to go is to compile with -DJS_THREADSAFE and register a callback with JS_SetGCCallback() that tells the VM when it's safe to run the garbage collector.

Actually, the approach I took was to always tell the VM 'no' and invoke JS_GC() manually from time to time. Conceptually easy and performance is mostly amortized.

PS: Feel free to contact me if you have follow-up questions, my email is in my profile.

Re:Node.js on mozilla spidermonkey by mraleph on Thursday April 21, 2011 @02:05PM (#2471617)
I think Mozilla is also making SpiderMonkey threading model more strict. https://developer.mozilla.org/en/JS_THREADSAFE says:

JS_THREADSAFE is now permanently on.

We have recently made major changes to this feature. Until recently, sharing objects among threads would mostly work, although scripts could easily make it crash. We have now completely removed that feature. Each thread that uses the JavaScript engine must essentially operate in a totally separate region of memory.

------

So both VMs provide essentially the same multithreading capabilities.

Re:Node.js on mozilla spidermonkey by vr on Thursday April 21, 2011 @12:42PM (#2471286)
V8 supported multiple threads since long ago using a big VM lock approach (v8::Locker). Since 3.2.4 it's possible to run independent V8 code in parallel using the new v8::Isolates API: http://code.google.com/p/v8/source/browse/trunk/include/v8.h...
Re:Node.js on mozilla spidermonkey by zpao on Friday April 22, 2011 @02:45AM (#2473435)
If you're interested in helping out, best thing to do is stop by the IRC channel and see what we need the most help with (or if you want to start more simple, we can point you at that too). We've been moving pretty quickly in the week since that went up.