Repository navigation
perf: faster objectMechanism 'native' for Date values and small arrays - #935
Merged
Merged
Conversation
Tony133
marked this pull request as ready for review
November 21, 2026 10:59
Tony133
force-pushed
the
perf/native-dates
branch
from
November 21, 2026 11:20
b166fcb to
c7f8ad5
Compare
This was referenced Nov 22, 2026
Open
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.
Proposal:
objectMechanism: 'native'faster when the data containsDatevalues.objectMechanism: 'native'.Problem:
With
objectMechanism: 'native', aDatewas converted withtoISOString()and then passed toJSON.stringify. On Node 26 this path is slower than the default mechanism: 41.8k ops/sec against 52.1k for a list of 50 rows with onedate-timecolumn. So the option made responses with dates slower instead of faster.There was also a small difference in behaviour. Since #929 the default mechanism ignores a
toISOString()overridden on aDatesubclass, whileobjectMechanism: 'native'still called it for astringwithoutformat.Change:
lib/serializer.js: newasDateTimeValue(date), which builds the ISO 8601 string with a singleString.fromCharCode(...)call.JSON.stringifyis much faster on a string built this way than on the one returned bytoISOString(). Years outside 0-9999 and invalid dates still go throughtoISOString(), so the output and the error are the same as before.lib/projection.js:date-timefields andstringfields withoutformatuseasDateTimeValuefor aDate.lib/projection.js: thelengthof a reused array is written only when it changes. The assignment has a cost even when the value is the same.Tests:
Datevalues indate-timefields and instringfields withoutformat, as a property, as a nullable type and inside an array:objectMechanism: 'native'gives the same output as the default mechanism. The cases include year 0 and year 9999, years outside that range, an invalid date and aDatesubclass that overridestoISOString().nullbetween two calls.Benchmark:
Node v26.12.0, Apple Silicon, ops/sec.
Note:
objectMechanism: 'native'is active only on Node 25+, so nothing changes on Node 22 and 24.Datesubclass that overridestoISOString()in astringfield withoutformat:objectMechanism: 'native'now ignores the override, as the default mechanism does since perf: format Date values in plain string schemas without toISOString #929.