-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need a way to serialize closure #32
Comments
That's not possible since it would
The only thing which might be possible would be cache variables, but these can already be defined in the function itself with spawn() and don't make any sense in map (because there's no shared state). |
Yeah, I guess that makes sense. Oh well. I guess we'll have to deal with it. |
Hi, not sure if i need to open a new thread, maybe this is related The problem is i want to use parallel.js inside an object instance for this library: https://github.com/foo123/HAAR.js The code is this right now (not in repository)
Trying to pass the object instance (this) as part of data, since it can not be passed as part of a callback DataCloneError: The object could not be cloned. i guess this refers to the "this" reference, any way to bypass this. The main idea is to parallelize a process Any ideas/help welcome Nikos |
You can only transmit parameters to webworkers which are supported by the structured cloning algorithm. That means you'd have to create your instance of the face detection library in the parallel function too. Remember this: You cannot access any variables which are not directly in your parameter list inside your spawned/mapped functions. |
Thanks for the fast response,i checked afterwards the types of objects supported by the structured cloning algorithm, Object is supported but a general class (Function) is not supported. Was trying to avoid re-instantiating the whole class a-new in each worker. Do you have, by any chance, any idea of how to best parallelize the task? Thanks again, |
Since I know nothing about face detection I'll have to pass on algorithmic questions, however if you really need your instance (and can't rewrite it) you'll have to re-instantiate. |
It's OK, thinking about using generic functions (without "this" reference) and use all the necessary data (which are arrays, objects or canvas) as parameters. Then if async computation is used, these generic functions can be called with this.data, else with the worker data The detection data are usually large (~1MB of data in an object structure), does this have any side-effects? In any case, once this is complete, it could also be an example of a real-world js application using parallel.js. |
Ah, I see, you have to initialize the detection library with some pre-initialized data? Regarding node: node has an additional restriction in that you can't use the full extent of structured cloning and you're restricted to types which are convertible to JSON. It might be possible to extend parallel with some special handling for ArrayBuffers, but I haven't looked at that yet. |
Yes, exactly, the detection is done using data which represent the feature to be detected (same as openCV) These exist usually in a separate js file which the user loads (depending on what is supposed to be detected) The easiest is just to clone this whole object, i am not sure if it is possible to determine the js file that contains the data (as it is user-defined), if that is the case it might be better to just require the file itself i am goin to try my luck ;) Thanks |
Finally added parallel.js support in HAAR.js (up to now seems fine, except some results might be slightly different when in parallel) https://github.com/foo123/HAAR.js Cheers |
Take memoized fibonacci:
Where we store computed values in closure scope...
Fails with the error, memo is not defined
The text was updated successfully, but these errors were encountered: