Skip to content

Commit 3c1c4c9

Browse files
authored
perf: cache parsers per column (#3568)
1 parent fc4de3c commit 3c1c4c9

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/pg-native/lib/build-result.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Result {
1010
this.fields = []
1111
this.rows = []
1212
this._prebuiltEmptyResultObject = null
13+
this._parsers = []
1314
}
1415

1516
consumeCommand(pq) {
@@ -21,13 +22,16 @@ class Result {
2122
const nfields = pq.nfields()
2223
this.fields = new Array(nfields)
2324
const row = {}
25+
this._parsers = new Array(nfields)
2426
for (let x = 0; x < nfields; x++) {
2527
const name = pq.fname(x)
2628
row[name] = null
29+
const typeId = pq.ftype(x)
2730
this.fields[x] = {
2831
name: name,
29-
dataTypeID: pq.ftype(x),
32+
dataTypeID: typeId,
3033
}
34+
this._parsers[x] = this._types.getTypeParser(typeId)
3135
}
3236
this._prebuiltEmptyResultObject = { ...row }
3337
}
@@ -61,8 +65,7 @@ class Result {
6165
if (rawValue === '' && pq.getisnull(rowIndex, colIndex)) {
6266
return null
6367
}
64-
const dataTypeId = this.fields[colIndex].dataTypeID
65-
return this._types.getTypeParser(dataTypeId)(rawValue)
68+
return this._parsers[colIndex](rawValue)
6669
}
6770
}
6871

0 commit comments

Comments
 (0)