-
Notifications
You must be signed in to change notification settings - Fork 13
Description
I received a couple inquiries for continued web worker support to help solve performance issues in two different cases:
- Issue when populating with data from one or more external servers.
- Issue when reading and processing binary/base64 image data from the database (ref: BLOB data support (MBTiles etc.) #10)
There is an existing version at https://github.com/litehelpers/Cordova-sqlite-evplus-legacy-workers-free but it has the following major problems:
- Extra communication overhead: response messages go through the main thread and there is library code to send each worker response messages to the correct worker thread.
- Standard Web SQL transaction API will not work with upcoming browser platform (ref: WIP: initial browser platform cordova-sqlite-storage#576).
- ADDITIONAL PROBLEM raised in Simultaneously Transactions with web workers and main app litehelpers/cordova-sqlite-evmax-ext-workers-legacy-build-free#3
The ideal solution would be to redesign the apps to move all processing and possibly XHR (HTTP requests) to web workers and reserve the main thread to handle DOM, coordination, and I/O tasks. (Note that this plugin already uses background threads to handle sqlite operations, with the exception of Windows which can easily be fixed.) Unfortunately this may not be a 100% solution since this plugin does have some internal pre/post processing in JavaScript.
The most general solution would be to offer the db.executeSql and db.sqlBatch functions within web workers. This solution would continue to have the extra communication overhead described above.
An alternative solution for case 1 would be to write the data from a worker and let the main thread listen for indications of data write success/failure results. This idea is inspired by existing ideas such as reactive programming and Flow Based Programming (FBP) as described by J. Paul Morrison.
For case 2 an alternative, recommended solution is to read the image data from the main thread and then send it to a web worker for further processing.