f5io / bonobo-js

A work-monkey to do your dirty business.
38 stars 4 forks source link

remove the need for Bonobo to be loaded through a <script> tag #7

Closed mhelvens closed 9 years ago

mhelvens commented 9 years ago

It seems that Bonobo expects to be loaded through a <script> tag, so that it can import itself to worker scripts. But this is not documented. It's also unfortunate, because I concatenate all my .js files into one. And even if I make an exception for Bonobo, the main script would have to be in the server's root to have the bonobo-path resolve properly.

If I understand Bonobo's principles correctly, you should be able to do away with this restriction. Could you put Bonobo's code inside a function, and then use .hoist to get it into the workers?

At the very least, it would be useful if I could manually specify the path where the lib could be found.

f5io commented 9 years ago

You are right and I have been thinking about this problem all wrong for a while.

You have the right idea tho :+1: so I will look at implementing this, this week.

mhelvens commented 9 years ago

Awesome.

(PS: I have to do some web-worker stuff before my deadline, which is in about 1.5 days. If there's any chance you could get a simple (even naive) version of this solution running soon, that would be great. I could beta-test for you. If not, totally understandable.)

f5io commented 9 years ago

Check this commit: 0be4e978f69e39976014c21f50b96e713a987318

It's a new branch, see how that works out.

mhelvens commented 9 years ago

Nice! Initial experiments are working perfectly. :-)

Tomorrow I'll try to do the actual implementation with Bonobo. That is: fetching and processing some 3D models. I'll keep you up to date.

f5io commented 9 years ago

Thats good to hear, I would like to clean it up a bit before releasing it.

mhelvens commented 9 years ago

I'm not finished with my web-worker stuff yet, because I've run into some problems. But those are not related to Bonobo, but to THREE.js. In fact, loading THREE.js in a worker thread, performing some operations and returning a non-cyclic object to the main thread, seem to be working fine. So kudos!

f5io commented 9 years ago

Cool, i'll get onto cleaning it up as soon as I can.

mhelvens commented 9 years ago

Turns out, maybe my problems were related to Bonobo after all. I'm not sure if it's this rewrite or not. I'm putting this here just in case.

If I try to send an array of a certain size through Bonobo.done(), I get a 'call stack size exceeded' error:

Uncaught RangeError: Maximum call stack size exceeded          bonobo.js:56

That's in the _.arrayBufferToString function. If I pass an array of, say, 5000 numbers, it gets through fine. If I pass 50000 numbers, I get the error.

Can you reproduce this? This happens for Chromium 40. It does not seem to happen for Firefox. Regardless, I'm surprised that there's any unbounded recursion going on in there when you'd expect iteration.

f5io commented 9 years ago

I will have a look at this today. Are the numbers in a TypedArray or a plain Array? Also are they floats or integers?

mhelvens commented 9 years ago

It's a plain array with floats. Thanks!

f5io commented 9 years ago

This commit should fix your issue: bd76904f611aba9323c2571bdb9e881b4e77b945

It seems String.fromCharCode.apply causes a stack overflow if the array that you pass in is too large, so I've had to refactor that slightly.

mhelvens commented 9 years ago

Seems to work. Thanks!