Skip to content

Conversation

sinclairzx81
Copy link
Contributor

Checklist

This PR should resolve inline $id references mentioned on issue #410. This implementation adds an additional schemaReferenceMap which is used to collect schemas with $id observed during the build phase. These references are later resolved in subsequent calls to the refFinder(...) function.

Note: There is some overlap here with the existing externalSchema variable which I think may be trying to resolve specifically for anchor (or #) references (I'm entirely not sure). I have left the externalSchema implementation as is as a fall through. It was noted however that the externalSchema variable was undefined for the inline $id / $ref code path.

This PR also adds the $id property to the TS definition for BaseSchema

Submitting for community review

Benchmark

CPU: AMD Ryzen 7 3700X
RAM: 16GB
OS: Windows 10

FJS creation x 7,030 ops/sec ±1.67% (92 runs sampled)
CJS creation x 152,803 ops/sec ±0.20% (94 runs sampled)
AJV Serialize creation x 87,669,032 ops/sec ±0.34% (94 runs sampled)
JSON.stringify array x 3,099 ops/sec ±0.45% (93 runs sampled)
fast-json-stringify array default x 7,551 ops/sec ±0.61% (93 runs sampled)
fast-json-stringify array json-stringify x 7,861 ops/sec ±0.32% (93 runs sampled)
compile-json-stringify array x 7,629 ops/sec ±0.92% (89 runs sampled)
AJV Serialize array x 8,418 ops/sec ±0.64% (95 runs sampled)
JSON.stringify large array x 154 ops/sec ±0.33% (87 runs sampled)
fast-json-stringify large array default x 104 ops/sec ±3.40% (68 runs sampled)
fast-json-stringify large array json-stringify x 153 ops/sec ±0.38% (86 runs sampled)
compile-json-stringify large array x 332 ops/sec ±0.42% (88 runs sampled)
AJV Serialize large array x 96.35 ops/sec ±0.22% (82 runs sampled)
JSON.stringify long string x 9,918 ops/sec ±0.18% (96 runs sampled)
fast-json-stringify long string x 9,991 ops/sec ±0.11% (96 runs sampled)
compile-json-stringify long string x 10,000 ops/sec ±0.09% (97 runs sampled)
AJV Serialize long string x 22,533 ops/sec ±0.72% (97 runs sampled)
JSON.stringify short string x 9,231,883 ops/sec ±0.47% (96 runs sampled)
fast-json-stringify short string x 45,670,735 ops/sec ±0.25% (98 runs sampled)
compile-json-stringify short string x 42,118,334 ops/sec ±0.86% (95 runs sampled)
AJV Serialize short string x 39,980,549 ops/sec ±0.32% (96 runs sampled)
JSON.stringify obj x 1,832,767 ops/sec ±0.74% (93 runs sampled)
fast-json-stringify obj x 11,078,004 ops/sec ±0.45% (97 runs sampled)
compile-json-stringify obj x 21,901,106 ops/sec ±1.34% (95 runs sampled)
AJV Serialize obj x 11,098,735 ops/sec ±1.29% (92 runs sampled)
JSON stringify date x 549,445 ops/sec ±0.23% (91 runs sampled)
fast-json-stringify date format x 898,135 ops/sec ±0.32% (96 runs sampled)
compile-json-stringify date format x 537,925 ops/sec ±0.41% (93 runs sampled)

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 0e16052 into fastify:master May 4, 2022
@sinclairzx81
Copy link
Contributor Author

@mcollina thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants