Settings

Theme

Show HN: JavaScript port of SQLite's parser, 2x-200x faster than others

github.com

2 points by jitl 12 days ago · 0 comments · 1 min read

Reader

I needed a SQLite parser small and fast enough to use in Notion's UI thread that I can trust will handle modern SQLite syntax. The most-downloaded SQLite parser on NPM is unfortunately unmaintained and slow, and while there are some fast and accurate WASM options, WASM pays a very large start-up cost as well as per-call overhead.

SQLite uses a LALR(1) parser generator call Lemon (similar to Yacc). I patched Lemon to dump its parse tables to JSON, then ported SQLite's [parse.y][] grammar to TypeScript with some help from Claude. The result is this library, which I think is the fastest JavaScript SQL parser out there:

      ~2.5x faster than liteparser (wasm)
      ~6x   faster than @guanmingchiu/sqlparser-ts (wasm)
     ~10x   faster than node-sql-parser
    ~100x   faster than pgsql-ast-parser
    ~200x   faster than sqlite-parser
    ~250x   faster than @appland/sql-parser
This shipped in Notion a few weeks ago and cleared up some sporadic crash reports where the library we previously used choked on valid input.

parse.y: https://github.com/justjake/sqlite3-parser-js/blob/main/vend...

No comments yet.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection