capacitor-community / sqlite

⚡Capacitor plugin for native & electron SQLite databases.
MIT License
485 stars 116 forks source link

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

Open folsze opened 2 weeks ago

folsze commented 2 weeks ago

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 commented 2 weeks ago

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).