Repository navigation
perf: project more schemas with objectMechanism 'native' - #936
Merged
Merged
Conversation
Tony133
marked this pull request as ready for review
November 21, 2026 11:27
mcollina
approved these changes
Nov 21, 2026
gurgunday
approved these changes
Nov 21, 2026
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Note:
objectMechanism: 'native'is active only on Node 25+, so nothing changes on Node 22 and 24.