Skip to content

Performance question? #163

@ebelevics

Description

@ebelevics

I'll make it short. I had one project which I migrated from sqflite to drift, while it did work I noticed that there were slight performance drops (around 0.1s). It might have been because my queries were not optimized... don't know.

Anyways I'll soon will have serious project and last two weeks am trying to find best DB solution. And one the main clients requests was performance. So I have analyzed multiple DB solutions: sqflite, sqlite3, drift, sqflite_common_ffi, realm, objectbox and isar.

While NoSQL solutions were more performant in speed, I have stumbled with some quirks, that was a no-go. In general I though SQL itself are significantly slower than NoSQL, until I tried sqlite3. To be honest I was surprised - it was on par in speed with NoSQL solution, where even querying 50000 table record it took 0.17 seconds, which was similar to NoSQL solutions.

Then I tried sqflite, sqlite3, drift and sqflite_common_ffi and I couldn't wrap my head around why for example I get these duration results:
On Empty table select all statement:
sqlite3 - 0:00:00.005121
sqflite_common_ffi - 0:00:00.380625
drift - 0:00:00.260545
sqflite - file is deleted, but I can return it for result inspection

Of course sqlite3 as I noticed method are not async compared to other solutions. So does it mean that isolates are the main cause of this performance drop? I did tried to create my own isolate in sqlite3 and got "0:00:00.119083" duration instead for same statement. It is useful of course to not block UI if DB operation is too heavy. Or maybe I'm missing something?

I you would like, I can create result with 50000 table records and show comparison, but at this moment I'll try to create sync and async (isolate) wrappers around sqlite3. Sync for light queries and statement, async for heavier queries. Similar how it's done in ObjectBox or Isar. But it's just a bummer that I have to then create a whole new API for this, while drift or sqflite has already fantastic years spent Sql wrapper API.

Tested devices were: Google Pixel 6a, LG G7 and iPhone SE, all had similar results.
Flutter 3.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions