← Back to Pull requests

perf: project more schemas with objectMechanism 'native' #936

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

Proposal:

  • Let objectMechanism: 'native' handle schemas that use nullable, enum, format or additionalProperties: false.

  • The default mechanism is not touched.
  • Problem:

    With objectMechanism: 'native', one of these keywords anywhere in the schema is enough to make the whole schema fall back to the default mechanism, without any notice. They are very common in response schemas (format: 'email', nullable: true, additionalProperties: false), so many users who enable the option get no gain at all. In the benchmark below the two fast-json-stringify v7.3.8 columns are the same for this reason.

    Change:

    lib/projection.js now projects:

  • additionalProperties: false (the default mechanism treats it like a missing additionalProperties);

  • nullable: true on strings, numbers, integers, booleans, objects and arrays: null is written as null;

  • enum when the schema also has a type (the default mechanism does not use it to serialize);

  • any format on a string except unsafe, which writes the string without escaping; format on the other types, which the default mechanism ignores.
  • Still left to the default mechanism: $ref, const, anyOf / oneOf / allOf, if, patternProperties, ['integer', 'null'].

    The README section on objectMechanism lists the new cases.

    Tests:

  • A new test compares objectMechanism: 'native' with the default mechanism on more than 3000 combinations of schema and value: same output or same error. Each type is tested with and without nullable, with enum, format and default, as a property, as a required property and as an array item, with null, missing values, wrong types, toJSON() and undeclared properties.

  • The lists of projectable and not projectable schemas in the existing tests are updated.

  • Coverage is 100% on Node 22, 24 and 26.
  • Benchmark:

    Node v26.13.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, 2 string formats (uuid, email) | 88.9k | 48.9k | 49.1k | 84.6k | +72.3% | +73.1% | -4.8% |
    | 50 rows x 8 columns, 1 enum | 88.8k | 49.1k | 49.4k | 84.8k | +71.7% | +72.8% | -4.6% |
    | 50 rows x 8 columns, 2 nullable strings, no null in the data | 89.7k | 48.9k | 49.2k | 85.3k | +73.4% | +74.2% | -4.9% |
    | 50 rows x 8 columns, 2 nullable strings, null in 1 row out of 3 | 89.5k | 50.6k | 50.6k | 85.1k | +68.2% | +68.2% | -5.0% |
    | 50 rows x 8 columns, all of the above and additionalProperties: false | 90.3k | 50.3k | 50.4k | 85.5k | +69.7% | +69.9% | -5.2% |
    | user object, all of the above, nullable nested object | 4.21M | 2.00M | 2.02M | 3.44M | +70.4% | +71.6% | -18.3% |
    | control: 50 rows x 8 columns, none of them | 89.2k | 49.2k | 83.6k | 83.9k | +0.3% | +70.4% | -5.9% |

    Note:

  • semver-patch: no API change, same output as the default mechanism.

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

  • Independent from #935: the two branches merge without conflicts, in any order.
  • Diff: 406 lines (+304 / -102) across 5 files Reviewer: gurgunday Review duration: 229m
    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 · 406 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 #936"
    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.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    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%