web-worker

Is multithreading with webworkers ineffective?

拥有回忆 提交于 2019-12-01 10:30:29
I have a project in which I have to process quite large objects, each taking about 500ms. I thought that using web workers would greatly speed up this process. But after playing around with web workers, they didn't seem to improve the speed at all - even if I took away the preprocessing the creation of the web workers. So I decided to create a simple example: there is an array with N numbers, and the sum of those numbers should be calculated. So first, without webworkers ( DEMO ): /** Goal: return sum of all numbers in array */ var numbers = []; for(var i = 0; i < N; i++){ numbers.push(Math

Is multithreading with webworkers ineffective?

强颜欢笑 提交于 2019-12-01 08:07:55
问题 I have a project in which I have to process quite large objects, each taking about 500ms. I thought that using web workers would greatly speed up this process. But after playing around with web workers, they didn't seem to improve the speed at all - even if I took away the preprocessing the creation of the web workers. So I decided to create a simple example: there is an array with N numbers, and the sum of those numbers should be calculated. So first, without webworkers (DEMO): /** Goal:

Converting Javascript 2d arrays to ArrayBuffer

余生颓废 提交于 2019-12-01 08:04:49
问题 I'm trying to use Web Workers to process large volumes of data, and when passing data back to the main thread for display, I would like to use a transferable object to reduce the impact on the UI thread. The procedure currently results in a multi dimensional array that can also contain objects. For instance: [{foo: [{bar: "Alice", car: 23, dab: [2, 3, 5]}], faa: [{moo: {a: [2,3], b: [4,5]} }, {moo: {a: [6,7], b: [8,9]} }]}, {foo: [{bar: "John", car: 33, dab: [6, 7, 1]}], faa: [{moo: {a: [5,5]

DOM-like APIs for HTML string content inside a web worker

。_饼干妹妹 提交于 2019-12-01 07:39:11
Is there any library that could help with html string manipulation inside a web worker ? What I'd like to be able to do is, inside a worker, have sizzle-type selector tool that would allow me to do things like: hString = "<div><img src='foo'></img></div>" imgSrc = $(hString).find("img").attr("src") // foo , without the DOM interaction. What you basically want is a pure Javascript DOM implementation on which top you could run jQuery and fellows One such implementation exists for Node.js https://github.com/tmpvar/jsdom It can spoof DOM window object, APIs and such. You could take the code, rip

DOM-like APIs for HTML string content inside a web worker

柔情痞子 提交于 2019-12-01 04:33:57
问题 Is there any library that could help with html string manipulation inside a web worker ? What I'd like to be able to do is, inside a worker, have sizzle-type selector tool that would allow me to do things like: hString = "<div><img src='foo'></img></div>" imgSrc = $(hString).find("img").attr("src") // foo , without the DOM interaction. 回答1: What you basically want is a pure Javascript DOM implementation on which top you could run jQuery and fellows One such implementation exists for Node.js

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

馋奶兔 提交于 2019-12-01 03:23:19
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 ? 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+! Using the new OffscreenCanvas API you can now create a WebGL context off of the main thread. For the sake of

Transfer file to webworker: DataCloneError: The object could not be cloned

情到浓时终转凉″ 提交于 2019-12-01 00:15:42
问题 I want to transfer a file from a form to a webworker. In chrome i simple can use this code to transfer a FileList-Object: worker.postMessage(files: array_files); But with Firefox i get this error: Transfer file to webworker: DataCloneError: The object could not be cloned. So i tried to use the Syntax for transferable objects. Something like this? var post = {files: array_files, file_ids: response.file_ids}; worker.postMessage(post, [post]); But with that i get this in Chrome Uncaught

How to transfer large objects using postMessage of webworker?

吃可爱长大的小学妹 提交于 2019-11-30 20:55:05
I have read that transferable objects can be transferred really fast using postmessage of web worker. According to this transferable objects are either arraybuffer or messageport. Question is, how do I convert say an arbitrary object that is of large size (30 mb) to a transferable object and pass it as an argument to postmessage. From what I understand I can convert my array to json string and then convert json string to raw byte data and store that inside of an array object. However, this seems to defeat the purpose of fast transferring. could someone enlighten me to pass an object as

Using Webworkers in angular app (service worker cache access of data in angular-cli)

不问归期 提交于 2019-11-30 18:49:13
I wish to run an function (in the background) using a worker. The data comes from a http request. I am using a mock calculation (e.data[0] * e.data[1] * xhrData.arr[3]) (replaced by a function returning the actual algo result) as below: var ajax = function() { var prom = new Promise(function(resolve, reject){ if (!!XMLHttpRequest) { var xhttp = new XMLHttpRequest(); xhttp.onload = function () { if (this.readyState == 4 && this.status == 200) { resolve(JSON.parse(this.responseText)); } }; // Cache Logic - Will be adding logic to check cache // if test.json is in cache. // If it is then fetch

Maximum running web worker html5 at the same

纵饮孤独 提交于 2019-11-30 14:32:29
Is there any maximum count of web worker that can be run at the same time? Thanks a lot. Yes and no. With Web Workers, there's no hard limit but you are limited by the available CPU and memory. There's a rather large amount of CPU and memory overhead that comes with each worker so you can bring the machine to a grind if you spin off a lot of workers. I'd say Web Workers are best used for "long running" background tasks of 100 milliseconds or more. The w3c doesn't mention any limitation (see http://www.w3.org/TR/workers/ ) But it depends on what you are wanting to do, the limit will be the