Run away memory use sending ArrayBuffers to workers
Categories
(Core :: JavaScript: GC, defect, P2)
Tracking
()
People
(Reporter: jonco, Unassigned, NeedInfo)
References
(Blocks 1 open bug, )
Details
(Whiteboard: [MemShrink:P3])
Attachments
(2 files)
| Reporter | ||
Comment 1•8 years ago
|
||
| Reporter | ||
Comment 2•8 years ago
|
||
Updated•8 years ago
|
Comment 3•8 years ago
|
||
Comment 4•8 years ago
|
||
Comment 5•8 years ago
|
||
Updated•8 years ago
|
Comment 6•8 years ago
|
||
| Reporter | ||
Comment 7•8 years ago
|
||
Comment 8•8 years ago
|
||
Updated•8 years ago
|
Comment 9•8 years ago
|
||
Comment 10•8 years ago
|
||
Comment 11•8 years ago
|
||
Comment 12•8 years ago
|
||
Comment 13•8 years ago
|
||
Comment 14•8 years ago
|
||
Comment 15•8 years ago
|
||
Comment 16•8 years ago
|
||
Comment 17•8 years ago
|
||
Comment 18•8 years ago
|
||
Comment 19•8 years ago
|
||
Comment 20•7 years ago
|
||
Comment 21•7 years ago
|
||
Comment 22•7 years ago
|
||
Comment 23•6 years ago
|
||
Updated•3 years ago
|
Comment 24•2 years ago
|
||
I use this feature pretty heavily, and found out that our site is crashing FireFox users' browsers.
I hid the feature behind a URL so you guys can test it out and reproduce it. I use a background web worker to render a spinning 2d planet, along with active weather effects; it's fairly simple, but does rely on transferring stuff around. It has a couple different modes depending on what the browser supports, I think it's using the main thread rendering version and just transferring the data down via transfer on array buffers (since ImageBitmap/offscreen rendering wasn't reliable or working yet on Firefox, I can't remember).
You can enable it here: https://planetminecraft.com/?firefox_bug
The top of the page's header will have what we call the Active Header.
Comment 25•2 years ago
|
||
We do video based augmented reality in javascript, so needless to say, we have had a need to frequently send video frames to web workers in order to perform computer vision efficiently at a high frame rate. I was able to determine ArrayBuffer garbage collection will not happen until the app is blurred, or in some cases it might intermittently happen when the CPU processing had dropped significantly. It may be waiting to schedule GC until it feels like it's a good time, but it was hard to determine why or when. I was able to implement a pause in CPU and animation updates and occasionally trigger it, while also verifying this was not from a memory leak of any kind by process of elimination. It would quickly accumulate to several GB an then kill the website.
The workaround is to serialize the data into a string when passing it back to and from the web worker process, but this is in no way ideal. I tried using transferable objects, and the issue still persisted. It was only after implementing serialization did it stop being a problem.
For anyone interested, here is the serialization workaround, albeit opencv matrices. object.data is the arraybufffer and there's a function to get the channels for opencv's Mat constructor.
export const serializeImage = (image:Mat):ImageBuffer=>{
const data = btoa(new Uint8Array(image.data).reduce((data, byte) => data + String.fromCharCode(byte), ''));
return {width:image.cols, height:image.rows, data, channels:image.channels()}
}
export const deserializeImage = (buffer:ImageBuffer)=>{
const data = Uint8Array.from(atob(buffer.data), c => c.charCodeAt(0));
return cv.matFromArray(buffer.height, buffer.width, getMatrixType(buffer), data);
}
It is entirely possible this is also related to CPU utilization, but I do not know anything about the GC algorithm.
Updated•1 year ago
|
Comment 26•1 year ago
|
||
I will check how this is affected by my work in bug 1822411.
Description
•