3 ms·
A WebWorker can free up the main thread so the UI doesn't grind to a halt. Unfortunately they might not help you here. Data in/out of the worker is string only[
by ficklepickle 5y ago
A WebWorker can free up the main thread so the UI doesn't grind to a halt. Unfortunately they might not help you here. Data in/out of the worker is string only[0], so the extra parsing/serializing usually ruins any perf benefit.
You can access indexedDB from the worker, though. So you load the DB from the main thread, then you can do the filtering from the worker. You could return indexes then fetch those from indexDB on the main thread.
None of this will help with parsing large strings though, you are probably stuck with doing that on the main thread. And it is also not going to reduce the total time to perform the work. But hopefully it will avoid pinning the main thread, because that is bad.
I really enjoy this stuff, so feel free to contact me if you wanna talk it through. My email address is in my profile.
[0] SharedArrayBuffers were recently re-enabled according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- markdog12 5y ago> Data in/out of the worker is string only[0] I don't think this is correct. You can pass lots of types in via postMessage(), including Objects, ArrayBuffers, even a Canvas context. Some objects are transferrable as well, that is, zero copy. As far as your point about still being stuck on the main thread, that may indeed be the case depending on the work. More info: https://stackoverflow.com/questions/19152772/how-to-pass-large-data-to-web-workers https://stackoverflow.com/questions/19152772/how-to-pass-lar...
- hsbauauvhabzb 5y agoThanks, I’ve got some other work to kick off first but I’ll reach out when I have time!