I have a lot of data arrays on my website. for example: an array of vertices, an array of colors, an array of sizes ...
I work with a lot of items. Up to tens of millions.
Before adding data to arrays, I need to process them. So far, I have been doing this in the main topic, and this has caused my site to freeze for X seconds. It froze due to processing and due to the addition of processed data to arrays.
Today I moved (done a lot of work) processing to web workers, but the processed data is added to the main stream. I managed to save processing freeze time, but not add.
Adding is simply done using array.push() or array.splice() .
I read several articles about how an array works, and found out when we add an element to the array, the array is completely copied to a new location in memory with the size of array.length + 1 and adds the value. This makes my data slow.
I also read that typed arrays are much faster. But for this, I would need to know the size of the array, which I do not know, and to create a large typed array with an additional counter and control the addition of elements in the middle (and not at the end of the array) there would be many code changes that I do not want to do in present.
So, in my question, I have a TypedArray that returns from a web worker, and I need to add it to a regular array. What is the best way to do this? (today I run in a loop and click one after another)
EDIT
An example of using a website: a client adds the number of elements, say 100,000. The source data of the elements is collected and sent to the employee. The worker processes all the information and sends the processed data in the form of a typed array (for use as portable objects). In the main stream, we add the processed data to arrays - to the end or to a specific index. 2nd round. the client will add another 100,000 items. sending to the employee and adding the result to the main stream arrays. The 3rd round can be 10 items, the 4th round 10000, the 5th round can remove the indices 10-2000, ...
javascript arrays multithreading web-worker typed-arrays
Raziza o
source share