jlongster / absurd-sql

sqlite3 in ur indexeddb (hopefully a better backend soon)
MIT License
4.15k stars 101 forks source link

Asincify version of SQL.js (no COOP required!) #59

Open quolpr opened 2 years ago

quolpr commented 2 years ago

I was able to achieve the same performance as absurd-sql has, but with asincify version of SQL.js(using wa-sqlite).

Here is the comparison:

https://user-images.githubusercontent.com/7958527/179220916-6d28aaa3-9ca4-453b-bccb-677aec516b83.mp4

And, you can also run some benchmarks at https://cerulean-bublanina-96bf3a.netlify.app/

The results are roughly the same, but no COOP is required anymore!

Here is the source code of backend https://github.com/trong-orm/wa-sqlite-web-backend/blob/main/src/IDBCachedWritesVFS.ts (it's a bit messy). I used the same tricks as absurd-sql do โ€” don't write till transaction finish, use cursor if sequence read.

The problem now is that wa-sqlite is under GPL3 license, so we need someone who make MIT version of wa-sqlite ๐Ÿ˜…

rhashimoto commented 2 years ago

wa-sqlite is not a version of SQL.js. No code is derived from SQL.js and it has a completely different API.

quolpr commented 2 years ago

Yep, you are right ๐Ÿ™‚. Just want to point, that there is another way to achieve a good sqlite performance with asyncify version of SQLite (if I am not wrong with benchmarking!). And I think it is related to absurd-sq somehow, because James wrote at article:

Another option would be to use Asyncify, an Emscripten technique for turning sync C calls into async ones. However, thereโ€™s no way Iโ€™m going to touch that. It works by transforming the entire code to unwind/rewind stacks, causing a massive perf hit and bloating the binary size. Itโ€™s just too invasive and would force SQLite to have an async API.

At https://jlongster.com/future-sql-web.

It also definitely bloats the size, but brotli version has not so much size difference. I took Oz version of sql.js, and wa-sqlite (which is already Oz) and made brotli of them:

image

The difference is ~60kb.