web-worker

Wait for several web workers to finish

寵の児 提交于 2019-12-10 14:04:00
问题 I have a script that creates several webworkers, these webworkers perform some work and send a message when they finish. The problem is I need to get the result from all of them and then compute a final solution. In other works, they work out a partial solution of the problem and the main thread uses those partial solutions to generate the final answer. How could I wait for all those threads to finish, is there something in Javascript like invokeAll in Java? More or less, what I have in my

The best performant way to push items into array?

让人想犯罪 __ 提交于 2019-12-10 04:01:45
问题 In my website i have many arrays with data. for example: vertices array, colors array, sizes array... I'm working with big amounts of items. Up to tens of millions. Before adding the data into the arrays I need to process it. Until now, I did it in the main thread and this made my website freeze for X seconds. It froze because of the processing and because of adding the processed data into the arrays. Today I 'moved' (did a lot of work) the processing into web workers, but the processed data

Web Workers - do they create actual threads?

房东的猫 提交于 2019-12-10 03:07:13
问题 I have always thought that web workers create separate threads, but today I ran into the spec on w3c website. Below is a citation about web workers: This allows for thread-like operation with message-passing as the coordination mechanism. The question is - if it is thread-like , not actual thread what is an advantage(performance wise) of using this technology? Any help will be appreciated! 回答1: Yes, web workers create actual threads (or processes, the spec is flexible on this). According to

Web Workers: SetInterval and SetTimeout reliability

吃可爱长大的小学妹 提交于 2019-12-10 02:20:33
问题 In a browser environment, setTimeout and setInterval aren't reliable for accuracy - where time sensitivity is an issue. Recently, we've been given requestAnimationFrame , which allows us to do a little better (in terms of performance.now() and its timestamps). Long story short - I decided to build a metronome in Javascript, and while it works, it's fairly inaccurate above a certain tempo. While compensating for late frames allows the tempo not to desync over time, the individual beats are

Webworker-threads: is it OK to use “require” inside worker?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 01:56:47
问题 (Using Sails.js) I am testing webworker-threads ( https://www.npmjs.com/package/webworker-threads ) for long running processes on Node and the following example looks good: var Worker = require('webworker-threads').Worker; var fibo = new Worker(function() { function fibo (n) { return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1; } this.onmessage = function (event) { try{ postMessage(fibo(event.data)); }catch (e){ console.log(e); } } }); fibo.onmessage = function (event) { //my return callback };

Web Workers - How To Import Modules

房东的猫 提交于 2019-12-10 00:38:13
问题 I am using ES2015 Import / Export modules. In my worker file, when I try to import functions like I normally do: worker.js import { a, b, c } from "./abc.js"; I get the error: SyntaxError: import declarations may only appear at top level of a module As I am exporting functions in my module 'abc.js', I am not sure how to use them using the old (& apparently on its way out) syntax: self.importScripts( "/app/abc.js" ); So, my question is, how do we use the new import module syntax with workers?

Unable to create Web Worker from inside webworker in Chrome

烈酒焚心 提交于 2019-12-09 18:25:25
问题 Using Chrome 17.0.963.46 m, I tried to create a new web worker from inside a web worker. But got a "Uncaught ReferenceError: Worker is not defined" Any info. on this? (Google throw surprisingly few links on creating web worker inside webworkers) 回答1: That is the current state even on Chrome 19 - here is the bug: http://code.google.com/p/chromium/issues/detail?id=31666 It's working on FF. 回答2: Creating workers within workers is not available in chrome. FF implemented this with the Example. See

WebWorkers execution appears to be much slower than the main thread

ぃ、小莉子 提交于 2019-12-09 17:46:23
问题 I have been working on optimizing some long running JAvaScript, and tried implementing WebWorkers. I have a collection of independent tasks to compute. In my initial test there are 80 tasks, and on the main thread the complete in 250ms. I thought that I could distribute the tasks across some web workers and get the time down to maybe 50ms. My data is geometry data structures that nest multiple typed arrays. I have methods that extract all the data to JSON + an array of ArrayBuffer objects,

Web Worker blocked by main thread in Chrome

自古美人都是妖i 提交于 2019-12-09 04:41:05
问题 I have a Web Worker. I wish to make periodic network requests with it. One thing I particularly want is to make these requests even if the main JS execution thread is blocked (eg by a window.alert). I'm using Chrome 38. However, when I attempt to make network requests in the worker, the requests appear to be blocked by the UI thread. Here is a contrived example to illustrate the problem: base.js: var worker = new Worker("/worker.js"); setTimeout(function() { console.log("begin blocking"); var

Using WebGL from inside a Web Worker: is it possible ? How?

久未见 提交于 2019-12-09 03:01:29
问题 I opened this matrix multiplication benchmarks and my browser (Firefox 7.0.1) froze until the benchmarks finished (I opened the page in an old Asus EeePC 1000H). I heard that web workers were invented to separate processing from displaying the web pages. Is it possible to make use of the Web Workers API to make WebGL not stall the whole web browser ? 回答1: Yes, on Firefox! https://hacks.mozilla.org/2016/01/webgl-off-the-main-thread/ We’re happy to announce WebGL in Web Workers in Firefox 44+!