← Back to Pull requests

perf: faster objectMechanism 'native' for Date values and small arrays #935

Closed
unknown closed this pull request without merging on Nov 21, 2026 15:33 UTC
View on GitHub
unknown unknown commented on Nov 21, 2026 10:57 UTC
Author

Proposal:

  • Make objectMechanism: 'native' faster when the data contains Date values.

  • Skip a useless write on the arrays reused by objectMechanism: 'native'.

  • The default mechanism is not touched.
  • Problem:

    With objectMechanism: 'native', a Date was converted with toISOString() and then passed to JSON.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 one date-time column. 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 a Date subclass, while objectMechanism: 'native' still called it for a string without format.

    Change:

  • lib/serializer.js: new asDateTimeValue(date), which builds the ISO 8601 string with a single String.fromCharCode(...) call. JSON.stringify is much faster on a string built this way than on the one returned by toISOString(). Years outside 0-9999 and invalid dates still go through toISOString(), so the output and the error are the same as before.

  • lib/projection.js: date-time fields and string fields without format use asDateTimeValue for a Date.

  • lib/projection.js: the length of a reused array is written only when it changes. The assignment has a cost even when the value is the same.
  • Tests:

  • Date values in date-time fields and in string fields without format, 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 a Date subclass that overrides toISOString().

  • Arrays that keep their length, grow, shrink and become null between two calls.

  • Coverage is 100% on Node 22, 24 and 26.
  • 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:

  • semver-patch: no API change, the default mechanism is not modified.

  • objectMechanism: 'native' is active only on Node 25+, so nothing changes on Node 22 and 24.

  • The only visible change is for a Date subclass that overrides toISOString() in a string field without format: objectMechanism: 'native' now ignores the override, as the default mechanism does since #929.
  • Diff: 402 lines (+301 / -101) across 5 files Reviewer: mcollina Review duration: 275m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.7% (MEDIUM) · Higher = larger blast radius
    44.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.7% · Safe to merge
    17.7%