perf: project more schemas with objectMechanism 'native' #936
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
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 #936"
general
weight: 0.35
gurgunday
Proposal:
objectMechanism: 'native'handle schemas that usenullable,enum,formatoradditionalProperties: false.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.jsnow projects:additionalProperties: false(the default mechanism treats it like a missingadditionalProperties);nullable: trueon strings, numbers, integers, booleans, objects and arrays:nullis written asnull;enumwhen the schema also has atype(the default mechanism does not use it to serialize);formaton a string exceptunsafe, which writes the string without escaping;formaton 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
objectMechanismlists the new cases.Tests:
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 withoutnullable, withenum,formatanddefault, as a property, as a required property and as an array item, withnull, missing values, wrong types,toJSON()and undeclared properties.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:
objectMechanism: 'native'is active only on Node 25+, so nothing changes on Node 22 and 24.