Patch Changes
-
ff7a4eaThanks @gajus! - Reduce heap allocations on hot query construction and result pathsSeveral internal paths allocated short-lived intermediate arrays/objects that are now avoided, with no change in behavior:
sql.join/sql.listno longer re-validate and copy the assembled values array — the members are already narrowed to SQL tokens or primitive value expressions while the fragment is built.sql.unnestno longer builds a separate values array and spreads the per-column bindings into it; the bindings array is returned directly.pool.record()builds the result object in a single pass instead ofObject.fromEntries(rows.map(...)), avoiding a[key, value]tuple allocation per row. The prototype-pollution safety for a__proto__key is preserved viaObject.defineProperty, and the result is still a normalObject.prototypeobject.sql.and/sql.orreuse a hoisted filter predicate instead of allocating a new closure on every call.
In an isolated benchmark the
recordtransform produced roughly 3x fewer garbage-collection scavenges (and ran ~3.6x faster) on a 1,000-row result, and thesql.joinvalue handling dropped from one array allocation per call to none. Real-world impact scales with how large and frequent these operations are; for I/O-bound workloads the gain is modest but free. -
Updated dependencies []:
- @slonik/driver@49.10.6
- @slonik/errors@49.10.6
- @slonik/pg-driver@49.10.6
- @slonik/sql-tag@49.10.6
- @slonik/utilities@49.10.6