Sqllite | Hackaday
Love it or hate it, the capabilities of your modern web browser are continually increasing in weird and savage ways. The ability of web applications to run offline requires a persistent local storage solution and for many IndexedDB is the only choice as it works on most browsers and provides a database-like interface. However, as [James Long] Found, IndexedDB is painfully slow on Chrome and limited in query capacity. He decided to bring a tool he was familiar with, SQLite, and integrate it into the web browser as nonsense-sql.
Why absurd? Partly because most browsers (not Chrome) implement IndexedDB on top of SQLite. So for many browsers this is just SQLite on top of IndexedDB on top of SQLite. Luckily for [James] there was already a project known as sql.js which uses emscripten to compile C-based SQLite into WebAssembly. However, sql.js uses in-memory storage media and all data is lost when refreshing the page. [James] fine-tuned SQLite’s block reading and writing method. Instead of being saved in memory, it added a layer to read and write blocks from IndexedDB. This means that only sections of the database need to be read, resulting in huge performance gains.
This brings us to the other reason why this is absurd. On chrome (as well as Firefox), absurd-sql beats IndexedDB on almost all benchmarks. A query like
SELECT SUM(*) FROM kv leads to amazing results.
So what’s the downside? Other than a fairly large WebAssembly file that needs to be downloaded (409KB) and cached, there really isn’t one. Of course, not all is rosy when it comes to web development. Native SQLite runs 2-3 times faster than absurd-sql, which shows how slow IndexedDB really is.
atomics.wait() allows the worker to block the execution of the main thread until the read or write is complete. From SQLite’s point of view, the operations are synchronous. IndexedDB provides transactions so that multiple connections can occur (for example, multiple open tabs). Multiple read-only transactions can occur in parallel, but only one read-write transaction can be in progress.
Why not open up your browser and start playing with it? You’re already doomed to learn WebAssembly anyway.