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

This plugin creates "long tasks" when used on the web, even for simple sql #579

Closed
folsze opened this issue Aug 27, 2024 · 3 comments
Closed
Labels
bug/fix Something isn't working needs: triage

Comments

@folsze
Copy link
Contributor

folsze commented Aug 27, 2024

On the web, when inspecting with slowdown CPU power, this plugin yields lots of long tasks, mainly due to sql-wasm usage.

The CPU power I set to 20x slowdown in google chrome performance tab.

Check the profiler image, all the red tasks are slow and all of them mainly due to sql-wasm:

image

All you need for reproducing this is cloning this repo:

https://github.com/jepiqueau/blog-tutorials-apps.git

Then run this project which I used in the above screenshot:
and adding a new entity with the plus:

https://github.com/jepiqueau/blog-tutorials-apps/tree/main/SQLite/Part-1/ionic7-angular-sqlite-app

So my questions:

  1. Am I correct with stating that this plugin is slow (on the web) ? I am testing out other similar simple websites with 20x CPU slowdown and they behave very fast still
  2. is this known that it is that slow?
  3. what can be done to make it faster? any settings in the sql-wasm?

Thanks for any info you can provide :)

@folsze folsze changed the title Realization: this plugin creates "long tasks" when used on the web This plugin creates "long tasks" when used on the web, even for simple sql Aug 27, 2024
@folsze
Copy link
Contributor Author

folsze commented Aug 28, 2024

I am now comparing the performance with a Dexie.js sample app and with Dexie.js there are no "long tasks" happening, with the same 20x CPU slowdown:

image

I used this example angular repo from here:

To make the comparison fair, I made both sample apps create a single simple new entity. The performance difference is very large imo. But I am new to web browser performance so please let me know if my experiment is flawed or anything

As you can see in the dexie.js image, the database operations in Dexie.js usually run 10x slower (roughly at 25ms, sometimes even less) than with capacitor-sqlite (even though both plugins use indexedDB afaik, but only capacitor-sqlite uses sql-wasm).

@github-staff github-staff deleted a comment from folsze Aug 28, 2024
@robingenz robingenz added bug/fix Something isn't working needs: triage labels Aug 29, 2024
@jepiqueau
Copy link
Collaborator

@folsze
As you mentioned, the plugin creates "long tasks," which is due to the sql-wasm.wasm file. Unfortunately, there isn’t much we can do about this since sql.js is currently the only solution designed specifically to run SQLite databases directly in the browser.

I also considered using better-sqlite3, which I use for the Electron plugin, but it is tailored for Node.js environments, allowing direct modifications to SQLite files on the server or local filesystem.

While Dexie.js can store data directly in IndexedDB, it doesn’t function as a SQLite database. Although one could potentially create a wrapper to bridge SQLite with Dexie, that falls well outside the scope of jeep-sqlite.

I hope this clarifies why jeep-sqlite was designed this way. We do have to accept the limitations imposed by the WebAssembly file.

Thank you for your understanding. Since there isn’t anything further we can do, I will go ahead and close the issue.

@mustafa0x
Copy link

Related thought: I know that absurd-sql achieved better performance than raw indexedDb. It does use sql-wasm if I understand correctly.

https://jlongster.com/future-sql-web#tradeoffs-what-tradeoffs

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/fix Something isn't working needs: triage
Projects
None yet
Development

No branches or pull requests

5 participants
@mustafa0x @robingenz @jepiqueau @folsze and others