Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New premium version with web worker support upon customer demand (under consideration) #11

Open
brodycj opened this issue Nov 14, 2016 · 6 comments

Comments

@brodycj
Copy link
Contributor

brodycj commented Nov 14, 2016

I received a couple inquiries for continued web worker support to help solve performance issues in two different cases:

  1. Issue when populating with data from one or more external servers.
  2. 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:

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.

@kristfal
Copy link

@brodybits Thanks for taking a look at this.

Part of the performance issue when reading blobs is stemming from Cordova itself. If you look at this timeline, you'll notice that pollOnce and buildPayload accounts for almost half of the time spent on the operation (this was recorded on a Galaxy S3, so performance is expected to be poor).

skjermbilde 2016-11-15 15 02 59

In the example above, the rest of the thread lock is caused by inflating the binary payload, which is trivial to do in a worker.

Offering db.executeSql from a worker, and circumventing any communication via the main thread (including the cordova callback) before we manually transfer the processed data to the main thread would be preferable. If you're able to provide something for testing within the next couple of months, we would gladly evaluate it as discussed per e-mail.

@brodycj
Copy link
Contributor Author

brodycj commented Nov 16, 2016

Thanks @kristfal for the feedback and performance timeline. It does help make the case for web worker support. On the technical side:

I think the only way to achieve the desired functionality for @kristfal on Android (case 2) is to use a custom URI handler that handles the request and returns the result, maybe synchronously. I suspect it would be a blocking call on the worker but would have to do some experimentation to confirm. I would also have to do some experimentation to confirm whether or not it would be possible to achieve the same functionality on iOS. (It should be no problem to match this functionality on Windows.)

The other consequence of this scenario is that it could not be integrated with browser platform support (storesafe/cordova-sqlite-storage#576).

I hope it will be possible to support both case 1 (populate with data from external servers) and case 2, assuming it will work across the supported platforms Android, iOS, Windows, and possibly macOS. Any comments from @screendriver?

@brodycj
Copy link
Contributor Author

brodycj commented Nov 30, 2016

Also the idea to write data from a worker and listen for success/failure results in the main thread could be tricky on the Windows platform. I would have to do some testing to see if this would work or not.

@brodycj
Copy link
Contributor Author

brodycj commented May 11, 2017

Yet another issue with using database.transaction within web workers ("transaction within a transaction") was reported in litehelpers/cordova-sqlite-evmax-ext-workers-legacy-build-free#3.

@brodycj
Copy link
Contributor Author

brodycj commented May 11, 2017

To clarify: in case someone orders a new evplus version with web worker support I would like to completely remove the standard database.transaction support from that version.

@yinyinmyo
Copy link

You recommend that database.executeSql (for SELECT and single-statement changes) and database.sqlBatch (for multi-statement changes) instead of database.transaction.I try it.But i can't it.Because i dont know how to handle transaction using database.sqlBatch without using db.transaction.Please,show me the way expecially code sample.

@brodycj brodycj changed the title New evplus version with web worker support (under consideration) New premium version with web worker support (under consideration) Jan 17, 2018
@brodycj brodycj changed the title New premium version with web worker support (under consideration) New premium version with web worker support upon customer demand (under consideration) Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants