Repository navigation
Conversation
Every query paid for two allocations it did not need: - The Query and NativeQuery constructors copied the caller's config with Object.getOwnPropertyDescriptors and Object.defineProperties, so that normalizeQueryConfig could write values and callback onto the copy without touching the caller's object (brianc#3720). The constructors now read the config as given and let values and a callback passed as arguments take precedence, with the same precedence as normalizeQueryConfig. The caller's config is still never written to, and getters and prototype properties are read as before. normalizeQueryConfig itself is unchanged. - Result.addFields built _prebuiltEmptyResultObject, an object keyed by column name, for every result set. Only object rows use it, so rowMode 'array' now skips it.
mcollina
marked this pull request as ready for review
November 22, 2026 10:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This removes two allocations that every query pays for and doesn't need. Both are visible in CPU profiles of workloads that run many small queries, especially with
rowMode: 'array'.The
QueryandNativeQueryconstructors copied the caller's config withObject.getOwnPropertyDescriptorsandObject.defineProperties. That copy exists so thatnormalizeQueryConfigcan writevaluesandcallbackwithout changing the caller's object (#3720), and it costs about 0.65 µs per query. The constructors now read the config as given.valuesand a callback passed as arguments take precedence, using the same rules asnormalizeQueryConfig. The caller's config is still never written to, and getters and prototype properties are read the same way as before.normalizeQueryConfigitself is unchanged, since it is reachable throughpg/lib/utils.Result.addFieldsbuilt_prebuiltEmptyResultObject, an object keyed by column name, for every result set. Only object rows use it, so inrowMode: 'array'it is now skipped.The table shows CPU time per operation: Node 24.18 on Apple Silicon, median of 5 interleaved runs against
master. The result benchmarks use six columns and one row with the default type parsers. Rows marked "unchanged" are controls whose code paths this PR doesn't touch.new Query(config)new Query(config, undefined, callback)new Query(text, values, callback), unchangednew Result('array'),addFields,parseRownew Result(),addFields,parseRow, unchanged