perf: project with objectMechanism 'native' #937
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 · 446 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.365
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #937"
general
weight: 0.35
gurgunday
Proposal:
objectMechanism: 'native'handle schemas that use$ref.Problem:
With
objectMechanism: 'native', a single$refanywhere in the schema makes the whole schema fall back to the default mechanism, without any notice.$refis how schemas are shared, withdefinitionsor with theschemaoption (what Fastify does withaddSchema), so these users get no gain from the option. In the benchmark below the two fast-json-stringify v7.3.9 columns are the same for this reason.Change:
lib/projection.jsresolves each$refwith the same function the default mechanism uses and projects the target as if it were written in place. It works for a definition of the same schema, for an external schema, for a$refto another$refand for a schema used more than once: each use has its own scratch.$ref; a$refwith other keywords next to it, which the default mechanism merges with the target (title,descriptionand the other annotations are fine); a schema that would expand to more than 1000 nodes.Locationas the default mechanism. This also fixes two small differences that are onmaintoday: a key with/or~was not escaped in the message (#/properties/a/binstead of#/properties/a~1b), and arequiredkey named like anObject.prototypemember (constructor) that is not inpropertieswas not checked.objectMechanismlists the new cases.Tests:
$refto definitions, to external schemas, to an anchor and to another$ref:objectMechanism: 'native'gives the same output or the same error as the default mechanism on more than 400 inputs.$ref,$refwith sibling keywords, targets that are not projectable and a schema over the node limit keep the default mechanism, with the same output.$refthat cannot be found.Benchmark:
Node v26.13.0, Apple Silicon, ops/sec.
| Case | JSON.stringify | fast-json-stringify v7.3.9 (default mechanism) | fast-json-stringify v7.3.9 (objectMechanism native) | This PR (objectMechanism native) | Difference | This PR vs default mechanism | This PR vs JSON.stringify |
|---|---|---|---|---|---|---|---|
| control: 50 rows x 8 columns, schema without $ref | 202.7k | 70.3k | 178.7k | 179.5k | +0.5% | +155.2% | -11.5% |
| 50 rows x 8 columns, items is a $ref to a definition | 202.3k | 68.0k | 67.7k | 184.3k | +172.4% | +170.9% | -8.9% |
| 50 rows x 8 columns, items is a $ref to a shared schema | 201.0k | 66.5k | 66.7k | 183.1k | +174.5% | +175.4% | -8.9% |
| control: 50 rows x 10 columns, schema without $ref | 102.5k | 36.3k | 91.7k | 91.4k | -0.4% | +152.0% | -10.9% |
| 50 rows x 10 columns, 2 of them a $ref to the same definition | 105.4k | 36.1k | 36.0k | 96.2k | +167.0% | +166.8% | -8.7% |
| user object with 2 $ref to a shared schema | 3.96M | 1.84M | 1.84M | 3.48M | +89.2% | +89.1% | -12.1% |
A schema with
$refis now as fast as the same schema written without it.Note:
objectMechanism: 'native'is active only on Node 25+, so nothing changes on Node 22 and 24.