How it is fast
What waw-sql does differently under the hood. None of it changes how your scripts are written.
The Lua side
- Fast Lua bridge. With the classic path, every query creates a function reference on both the Lua and the JS side, and every reply starts a new Lua coroutine. waw-sql's Lua library opens one channel per resource: queries carry only a number, and results travel back to Lua in batches. Cached results are returned immediately, inside the same call. A channel belongs to the resource that opened it: no other script can send through it or close it.
- Fast result encoder. FiveM's own JS encoder for data going to Lua is slow on large results. waw-sql writes exactly the same bytes with its own encoder, 2 to 5 times faster, and Lua receives exactly the same tables.
- No promise per query.
MySQL.x.awaitwaits with FiveM's native await mechanism directly instead of building a promise for every query. It behaves the same asCitizen.Await. - Requests in batches. While waw-sql hands results to a resource, the queries that the resumed threads send right away are collected and passed to the engine in one call.
The database side
- SELECT batching under load. Frequent, fast, side-effect-free SELECTs use a few separate connections. When those are busy, the waiting SELECTs are sent together in one packet instead of one network write each. Strict rules apply:
- Only single, comment-free SELECTs without locks, variables or side-effect functions qualify, and only query shapes already measured as fast.
- Each query still runs exactly once and gets exactly its own result or error.
- A query that waits too long goes to the normal pool.
- The main pool's settings (for example, multi-statements stay off) do not change.
- Turn it off with
set waw_sql_coalesce false.
- Bigger, pre-opened connection pool. 20 connections by default, all opened on start.
- Cheaper type conversion. Only the columns that need it (dates, booleans, binary) are converted.
- Identical SELECTs sent at the same moment run once, and the result is shared. This is safe: a read never receives a result that started before a write it should see.
- Multi-row
MySQL.preparewrites use one transaction and one commit instead of one commit per row. - Multi-row
MySQL.preparereads run in parallel.
The measured numbers are on the SQL page in the store.
