From fdcdf295507e916cce17aec4879eeb71d2206532 Mon Sep 17 00:00:00 2001 From: Nigro Simone Date: Sun, 14 Dec 2025 19:11:58 +0100 Subject: [PATCH] perf: cache parsers per column --- packages/pg-native/lib/build-result.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/pg-native/lib/build-result.js b/packages/pg-native/lib/build-result.js index 7dffc3f9e..9117a11ef 100644 --- a/packages/pg-native/lib/build-result.js +++ b/packages/pg-native/lib/build-result.js @@ -10,6 +10,7 @@ class Result { this.fields = [] this.rows = [] this._prebuiltEmptyResultObject = null + this._parsers = [] } consumeCommand(pq) { @@ -21,13 +22,16 @@ class Result { const nfields = pq.nfields() this.fields = new Array(nfields) const row = {} + this._parsers = new Array(nfields) for (let x = 0; x < nfields; x++) { const name = pq.fname(x) row[name] = null + const typeId = pq.ftype(x) this.fields[x] = { name: name, - dataTypeID: pq.ftype(x), + dataTypeID: typeId, } + this._parsers[x] = this._types.getTypeParser(typeId) } this._prebuiltEmptyResultObject = { ...row } } @@ -61,8 +65,7 @@ class Result { if (rawValue === '' && pq.getisnull(rowIndex, colIndex)) { return null } - const dataTypeId = this.fields[colIndex].dataTypeID - return this._types.getTypeParser(dataTypeId)(rawValue) + return this._parsers[colIndex](rawValue) } }