perf: faster objectMechanism 'native' for Date values and small arrays #935
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 402 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.359
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #935"
general
weight: 0.35
mcollina
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.
| Case | JSON.stringify | fast-json-stringify v7.3.8 (default mechanism) | fast-json-stringify v7.3.8 (objectMechanism native) | This PR (objectMechanism native) | Difference | This PR vs default mechanism | This PR vs JSON.stringify |
|---|---|---|---|---|---|---|---|
| 50 rows x 8 columns, 1 date-time | 26.6k | 52.1k | 41.8k | 111.8k | +167.7% | +114.4% | +320.7% |
| 50 rows x 8 columns, 2 date-time | 15.2k | 35.1k | 20.4k | 55.3k | +171.1% | +57.8% | +263.7% |
| 50 rows x 8 columns, 2 Date in a string without format | 15.4k | 34.8k | 20.4k | 54.5k | +167.3% | +56.4% | +254.3% |
| user object with 1 date-time | 679.6k | 1.89M | 1.54M | 3.01M | +95.7% | +58.9% | +342.8% |
| user object, array of 3 strings, no date | 4.80M | 2.65M | 4.12M | 4.40M | +6.8% | +66.0% | -8.2% |
| control: 50 rows x 8 columns, no date | 96.3k | 56.0k | 91.9k | 91.7k | -0.3% | +63.8% | -4.8% |
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 #929.