Skip to content

Conversation

L2jLiga
Copy link
Contributor

@L2jLiga L2jLiga commented Dec 17, 2020

Adds support for const keyword

Fixes #275

References: http://json-schema.org/understanding-json-schema/reference/generic.html#id5

Checklist

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

@L2jLiga L2jLiga force-pushed the feature/const-value branch 2 times, most recently from 322fd60 to a5189a6 Compare December 17, 2020 11:44
index.js Outdated
Comment on lines 215 to 217
return (/"if":{/.test(str) && /"then":{/.test(str)) ||
/"(anyOf|oneOf)":\[/.test(str) ||
/"const":/.test(str)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zekth here's the same what hasOf, hasIf and hasConst does, do you see any tricky cases?

Copy link
Member

@zekth zekth Dec 17, 2020

Choose a reason for hiding this comment

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

Can't the first condition be factorized by :

/"if":{.*"then":{/.test(str)

WDYT?
Also is there any impact on perfs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried run benchmark, seems there no impact almost at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I joined all regexp into one

@L2jLiga L2jLiga force-pushed the feature/const-value branch from a5189a6 to 70faaeb Compare December 17, 2020 12:31
@L2jLiga
Copy link
Contributor Author

L2jLiga commented Dec 17, 2020

Windows 10 20H2 x64, AMD Ryzen 3500, 32gb RAM, NodeJS 14.15.2

master:

FJS creation x 44,960 ops/sec ±0.64% (90 runs sampled)
CJS creation x 132,537 ops/sec ±0.40% (91 runs sampled)
JSON.stringify array x 3,003 ops/sec ±0.46% (90 runs sampled)
fast-json-stringify array x 7,791 ops/sec ±0.35% (94 runs sampled)
compile-json-stringify array x 6,848 ops/sec ±0.67% (86 runs sampled)
JSON.stringify long string x 6,926 ops/sec ±0.53% (88 runs sampled)
fast-json-stringify long string x 6,874 ops/sec ±0.51% (87 runs sampled)
compile-json-stringify long string x 6,910 ops/sec ±0.63% (88 runs sampled)
JSON.stringify short string x 7,482,311 ops/sec ±0.44% (93 runs sampled)
fast-json-stringify short string x 42,011,320 ops/sec ±0.27% (93 runs sampled)
compile-json-stringify short string x 32,998,545 ops/sec ±0.44% (90 runs sampled)
JSON.stringify obj x 1,528,236 ops/sec ±0.39% (91 runs sampled)
fast-json-stringify obj x 7,692,684 ops/sec ±0.35% (93 runs sampled)
compile-json-stringify obj x 17,273,199 ops/sec ±1.01% (94 runs sampled)

this branch:

FJS creation x 47,992 ops/sec ±0.31% (94 runs sampled)
CJS creation x 133,213 ops/sec ±0.24% (93 runs sampled)
JSON.stringify array x 3,002 ops/sec ±0.43% (93 runs sampled)
fast-json-stringify array x 7,500 ops/sec ±0.31% (94 runs sampled)
compile-json-stringify array x 5,986 ops/sec ±0.55% (91 runs sampled)
JSON.stringify long string x 6,981 ops/sec ±0.48% (87 runs sampled)
fast-json-stringify long string x 7,020 ops/sec ±0.40% (89 runs sampled)
compile-json-stringify long string x 6,974 ops/sec ±0.41% (88 runs sampled)
JSON.stringify short string x 7,510,955 ops/sec ±0.33% (94 runs sampled)
fast-json-stringify short string x 42,628,500 ops/sec ±0.32% (93 runs sampled)
compile-json-stringify short string x 35,977,005 ops/sec ±0.34% (95 runs sampled)
JSON.stringify obj x 1,555,885 ops/sec ±0.54% (90 runs sampled)
fast-json-stringify obj x 7,825,478 ops/sec ±0.46% (96 runs sampled)
compile-json-stringify obj x 18,655,018 ops/sec ±0.99% (96 runs sampled)

P.S. I wouldn't really trust this benchmark results, there're lot of things which may accidentically affect them

Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

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

LGTM

regarding benchmarks, i just wanted to see if there is an impact from looping to regex.

@mcollina mcollina merged commit c9f7b53 into master Dec 17, 2020
@mcollina mcollina deleted the feature/const-value branch December 17, 2020 18:03
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.

Support "const" keyword
3 participants