-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(*): implement json type system #55
Conversation
f29d8fa
to
9a95448
Compare
Running the above benchmarks through ns/op bench comparisonbenchmark old ns/op new ns/op delta BenchmarkAdditionalItems/sample_size_1-8 411 400 -2.68% BenchmarkAdditionalItems/sample_size_10-8 2261 2413 +6.72% BenchmarkAdditionalItems/sample_size_100-8 21225 22550 +6.24% BenchmarkAdditionalItems/sample_size_1000-8 241823 259886 +7.47% BenchmarkAdditionalProperties/sample_size_1-8 571 4163 +629.07% BenchmarkAdditionalProperties/sample_size_10-8 4278 14283 +233.87% BenchmarkAdditionalProperties/sample_size_100-8 105712 157243 +48.75% BenchmarkAdditionalProperties/sample_size_1000-8 8885443 10425760 +17.34% BenchmarkConst/sample_size_1-8 1141 2403 +110.60% BenchmarkConst/sample_size_10-8 6168 12383 +100.76% BenchmarkConst/sample_size_100-8 58875 123338 +109.49% BenchmarkConst/sample_size_1000-8 643018 1390451 +116.24% BenchmarkContains/sample_size_1-8 496 1009 +103.43% BenchmarkContains/sample_size_10-8 9214 14293 +55.12% BenchmarkContains/sample_size_100-8 98430 155046 +57.52% BenchmarkContains/sample_size_1000-8 1010793 1635063 +61.76% BenchmarkDependencies/sample_size_1-8 404 532 +31.68% BenchmarkDependencies/sample_size_10-8 602 1645 +173.26% BenchmarkDependencies/sample_size_100-8 2200 13244 +502.00% BenchmarkDependencies/sample_size_1000-8 26662 119900 +349.70% BenchmarkEnum/sample_size_1-8 415 933 +124.82% BenchmarkEnum/sample_size_10-8 5131 7833 +52.66% BenchmarkEnum/sample_size_100-8 46125 69402 +50.47% BenchmarkEnum/sample_size_1000-8 455323 681553 +49.69% BenchmarkMaximum/sample_size_1-8 46.2 40.6 -12.12% BenchmarkMaximum/sample_size_10-8 46.2 41.0 -11.26% BenchmarkMaximum/sample_size_100-8 46.7 40.4 -13.49% BenchmarkMaximum/sample_size_1000-8 46.5 41.6 -10.54% BenchmarkMinimum/sample_size_1-8 46.7 41.3 -11.56% BenchmarkMinimum/sample_size_10-8 46.7 40.8 -12.63% BenchmarkMinimum/sample_size_100-8 47.0 41.1 -12.55% BenchmarkMinimum/sample_size_1000-8 46.9 41.6 -11.30% BenchmarkExclusiveMaximum/sample_size_1-8 46.6 40.5 -13.09% BenchmarkExclusiveMaximum/sample_size_10-8 46.7 40.9 -12.42% BenchmarkExclusiveMaximum/sample_size_100-8 45.7 41.1 -10.07% BenchmarkExclusiveMaximum/sample_size_1000-8 46.1 41.6 -9.76% BenchmarkExclusiveMinimum/sample_size_1-8 45.1 40.1 -11.09% BenchmarkExclusiveMinimum/sample_size_10-8 46.6 40.2 -13.73% BenchmarkExclusiveMinimum/sample_size_100-8 44.9 41.3 -8.02% BenchmarkExclusiveMinimum/sample_size_1000-8 46.0 41.3 -10.22% BenchmarkMaxItems/sample_size_1-8 46.0 40.6 -11.74% BenchmarkMaxItems/sample_size_10-8 47.1 40.2 -14.65% BenchmarkMaxItems/sample_size_100-8 46.3 39.8 -14.04% BenchmarkMaxItems/sample_size_1000-8 46.2 40.1 -13.20% BenchmarkMinItems/sample_size_1-8 45.7 41.7 -8.75% BenchmarkMinItems/sample_size_10-8 46.1 40.5 -12.15% BenchmarkMinItems/sample_size_100-8 45.5 40.7 -10.55% BenchmarkMinItems/sample_size_1000-8 45.7 39.5 -13.57% BenchmarkMaxLength/sample_size_1-8 47.9 43.1 -10.02% BenchmarkMaxLength/sample_size_10-8 52.2 47.1 -9.77% BenchmarkMaxLength/sample_size_100-8 115 106 -7.83% BenchmarkMaxLength/sample_size_1000-8 614 565 -7.98% BenchmarkMinLength/sample_size_1-8 48.5 42.6 -12.16% BenchmarkMinLength/sample_size_10-8 52.5 47.1 -10.29% BenchmarkMinLength/sample_size_100-8 117 104 -11.11% BenchmarkMinLength/sample_size_1000-8 608 580 -4.61% BenchmarkMaxProperties/sample_size_1-8 45.8 49.4 +7.86% BenchmarkMaxProperties/sample_size_10-8 46.1 48.8 +5.86% BenchmarkMaxProperties/sample_size_100-8 45.1 52.4 +16.19% BenchmarkMaxProperties/sample_size_1000-8 45.3 51.6 +13.91% BenchmarkMinProperties/sample_size_1-8 45.9 49.2 +7.19% BenchmarkMinProperties/sample_size_10-8 45.1 49.7 +10.20% BenchmarkMinProperties/sample_size_100-8 44.8 48.9 +9.15% BenchmarkMinProperties/sample_size_1000-8 45.0 51.1 +13.56% BenchmarkMultipleOf/sample_size_1-8 44.8 43.1 -3.79% BenchmarkMultipleOf/sample_size_10-8 46.7 42.1 -9.85% BenchmarkMultipleOf/sample_size_100-8 46.3 42.4 -8.42% BenchmarkMultipleOf/sample_size_1000-8 46.1 42.4 -8.03% BenchmarkPattern/sample_size_1-8 245 229 -6.53% BenchmarkPattern/sample_size_10-8 433 390 -9.93% BenchmarkPattern/sample_size_100-8 2184 1840 -15.75% BenchmarkPattern/sample_size_1000-8 19968 19207 -3.81% BenchmarkType/sample_size_1-8 2233 6459 +189.25% BenchmarkType/sample_size_10-8 23057 43821 +90.06% BenchmarkType/sample_size_100-8 261737 408302 +56.00% BenchmarkType/sample_size_1000-8 2859282 4176650 +46.07% allocation bench comparisonbenchmark old allocs new allocs delta BenchmarkAdditionalItems/sample_size_1-8 5 5 +0.00% BenchmarkAdditionalItems/sample_size_10-8 32 41 +28.12% BenchmarkAdditionalItems/sample_size_100-8 302 401 +32.78% BenchmarkAdditionalItems/sample_size_1000-8 3902 4901 +25.60% BenchmarkAdditionalProperties/sample_size_1-8 5 16 +220.00% BenchmarkAdditionalProperties/sample_size_10-8 32 88 +175.00% BenchmarkAdditionalProperties/sample_size_100-8 302 808 +167.55% BenchmarkAdditionalProperties/sample_size_1000-8 3002 8008 +166.76% BenchmarkConst/sample_size_1-8 13 28 +115.38% BenchmarkConst/sample_size_10-8 68 131 +92.65% BenchmarkConst/sample_size_100-8 616 1137 +84.58% BenchmarkConst/sample_size_1000-8 6037 11082 +83.57% BenchmarkContains/sample_size_1-8 3 6 +100.00% BenchmarkContains/sample_size_10-8 85 150 +76.47% BenchmarkContains/sample_size_100-8 1094 1879 +71.76% BenchmarkContains/sample_size_1000-8 10994 18980 +72.64% BenchmarkDependencies/sample_size_1-8 4 7 +75.00% BenchmarkDependencies/sample_size_10-8 4 25 +525.00% BenchmarkDependencies/sample_size_100-8 4 205 +5025.00% BenchmarkDependencies/sample_size_1000-8 4 2005 +50025.00% BenchmarkEnum/sample_size_1-8 2 5 +150.00% BenchmarkEnum/sample_size_10-8 42 77 +83.33% BenchmarkEnum/sample_size_100-8 483 839 +73.71% BenchmarkEnum/sample_size_1000-8 4983 8489 +70.36% BenchmarkMaximum/sample_size_1-8 0 0 +0.00% BenchmarkMaximum/sample_size_10-8 0 0 +0.00% BenchmarkMaximum/sample_size_100-8 0 0 +0.00% BenchmarkMaximum/sample_size_1000-8 0 0 +0.00% BenchmarkMinimum/sample_size_1-8 0 0 +0.00% BenchmarkMinimum/sample_size_10-8 0 0 +0.00% BenchmarkMinimum/sample_size_100-8 0 0 +0.00% BenchmarkMinimum/sample_size_1000-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_1-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_10-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_100-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_1000-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_1-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_10-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_100-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_1000-8 0 0 +0.00% BenchmarkMaxItems/sample_size_1-8 0 0 +0.00% BenchmarkMaxItems/sample_size_10-8 0 0 +0.00% BenchmarkMaxItems/sample_size_100-8 0 0 +0.00% BenchmarkMaxItems/sample_size_1000-8 0 0 +0.00% BenchmarkMinItems/sample_size_1-8 0 0 +0.00% BenchmarkMinItems/sample_size_10-8 0 0 +0.00% BenchmarkMinItems/sample_size_100-8 0 0 +0.00% BenchmarkMinItems/sample_size_1000-8 0 0 +0.00% BenchmarkMaxLength/sample_size_1-8 0 0 +0.00% BenchmarkMaxLength/sample_size_10-8 0 0 +0.00% BenchmarkMaxLength/sample_size_100-8 0 0 +0.00% BenchmarkMaxLength/sample_size_1000-8 0 0 +0.00% BenchmarkMinLength/sample_size_1-8 0 0 +0.00% BenchmarkMinLength/sample_size_10-8 0 0 +0.00% BenchmarkMinLength/sample_size_100-8 0 0 +0.00% BenchmarkMinLength/sample_size_1000-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_1-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_10-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_100-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_1000-8 0 0 +0.00% BenchmarkMinProperties/sample_size_1-8 0 0 +0.00% BenchmarkMinProperties/sample_size_10-8 0 0 +0.00% BenchmarkMinProperties/sample_size_100-8 0 0 +0.00% BenchmarkMinProperties/sample_size_1000-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_1-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_10-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_100-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_1000-8 0 0 +0.00% BenchmarkPattern/sample_size_1-8 2 2 +0.00% BenchmarkPattern/sample_size_10-8 2 2 +0.00% BenchmarkPattern/sample_size_100-8 2 2 +0.00% BenchmarkPattern/sample_size_1000-8 2 2 +0.00% BenchmarkType/sample_size_1-8 19 40 +110.53% BenchmarkType/sample_size_10-8 181 364 +101.10% BenchmarkType/sample_size_100-8 1801 3604 +100.11% BenchmarkType/sample_size_1000-8 18001 36004 +100.01% bytes bench comparisonbenchmark old bytes new bytes delta BenchmarkAdditionalItems/sample_size_1-8 52 52 +0.00% BenchmarkAdditionalItems/sample_size_10-8 232 336 +44.83% BenchmarkAdditionalItems/sample_size_100-8 2248 3216 +43.06% BenchmarkAdditionalItems/sample_size_1000-8 27448 39216 +42.87% BenchmarkAdditionalProperties/sample_size_1-8 54 4102 +7496.30% BenchmarkAdditionalProperties/sample_size_10-8 256 5024 +1862.50% BenchmarkAdditionalProperties/sample_size_100-8 2428 14403 +493.20% BenchmarkAdditionalProperties/sample_size_1000-8 26613 110580 +315.51% BenchmarkConst/sample_size_1-8 720 1520 +111.11% BenchmarkConst/sample_size_10-8 2134 4766 +123.34% BenchmarkConst/sample_size_100-8 20591 45159 +119.31% BenchmarkConst/sample_size_1000-8 267220 580925 +117.40% BenchmarkContains/sample_size_1-8 208 392 +88.46% BenchmarkContains/sample_size_10-8 3170 5291 +66.91% BenchmarkContains/sample_size_100-8 33511 55881 +66.75% BenchmarkContains/sample_size_1000-8 336124 568191 +69.04% BenchmarkDependencies/sample_size_1-8 38 86 +126.32% BenchmarkDependencies/sample_size_10-8 38 374 +884.21% BenchmarkDependencies/sample_size_100-8 38 3254 +8463.16% BenchmarkDependencies/sample_size_1000-8 38 32054 +84252.63% BenchmarkEnum/sample_size_1-8 176 360 +104.55% BenchmarkEnum/sample_size_10-8 1657 2898 +74.89% BenchmarkEnum/sample_size_100-8 15306 26644 +74.08% BenchmarkEnum/sample_size_1000-8 152206 264422 +73.73% BenchmarkMaximum/sample_size_1-8 0 0 +0.00% BenchmarkMaximum/sample_size_10-8 0 0 +0.00% BenchmarkMaximum/sample_size_100-8 0 0 +0.00% BenchmarkMaximum/sample_size_1000-8 0 0 +0.00% BenchmarkMinimum/sample_size_1-8 0 0 +0.00% BenchmarkMinimum/sample_size_10-8 0 0 +0.00% BenchmarkMinimum/sample_size_100-8 0 0 +0.00% BenchmarkMinimum/sample_size_1000-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_1-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_10-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_100-8 0 0 +0.00% BenchmarkExclusiveMaximum/sample_size_1000-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_1-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_10-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_100-8 0 0 +0.00% BenchmarkExclusiveMinimum/sample_size_1000-8 0 0 +0.00% BenchmarkMaxItems/sample_size_1-8 0 0 +0.00% BenchmarkMaxItems/sample_size_10-8 0 0 +0.00% BenchmarkMaxItems/sample_size_100-8 0 0 +0.00% BenchmarkMaxItems/sample_size_1000-8 0 0 +0.00% BenchmarkMinItems/sample_size_1-8 0 0 +0.00% BenchmarkMinItems/sample_size_10-8 0 0 +0.00% BenchmarkMinItems/sample_size_100-8 0 0 +0.00% BenchmarkMinItems/sample_size_1000-8 0 0 +0.00% BenchmarkMaxLength/sample_size_1-8 0 0 +0.00% BenchmarkMaxLength/sample_size_10-8 0 0 +0.00% BenchmarkMaxLength/sample_size_100-8 0 0 +0.00% BenchmarkMaxLength/sample_size_1000-8 0 0 +0.00% BenchmarkMinLength/sample_size_1-8 0 0 +0.00% BenchmarkMinLength/sample_size_10-8 0 0 +0.00% BenchmarkMinLength/sample_size_100-8 0 0 +0.00% BenchmarkMinLength/sample_size_1000-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_1-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_10-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_100-8 0 0 +0.00% BenchmarkMaxProperties/sample_size_1000-8 0 0 +0.00% BenchmarkMinProperties/sample_size_1-8 0 0 +0.00% BenchmarkMinProperties/sample_size_10-8 0 0 +0.00% BenchmarkMinProperties/sample_size_100-8 0 0 +0.00% BenchmarkMinProperties/sample_size_1000-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_1-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_10-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_100-8 0 0 +0.00% BenchmarkMultipleOf/sample_size_1000-8 0 0 +0.00% BenchmarkPattern/sample_size_1-8 152 152 +0.00% BenchmarkPattern/sample_size_10-8 160 160 +0.00% BenchmarkPattern/sample_size_100-8 256 256 +0.00% BenchmarkPattern/sample_size_1000-8 1168 1168 +0.00% BenchmarkType/sample_size_1-8 150 2460 +1540.00% BenchmarkType/sample_size_10-8 1360 6612 +386.18% BenchmarkType/sample_size_100-8 14396 48407 +236.25% BenchmarkType/sample_size_1000-8 159515 489146 +206.65% narrowing in on the
Allocations are tracking consistently across sample sizes. Speed seems to be on a collision course as we move up the sample size, which is great to see. In my opinion the value of this feature may be worth the slowdown, so I think the next thing to do is a sanity check of perceived performance slowdowns. a |
@asido As |
b.Grow(n) | ||
b.WriteString(mapTStr[ts[0]]) | ||
for _, t := range ts[1:] { | ||
b.WriteString(",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b.WriteByte(',')
n += len(mapTStr[ts[i]]) | ||
} | ||
|
||
var b strings.Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the final length is known, the dynamic nature of strings.Builder
doesn't seem necessary. Using directly a []byte
should be enough.
given that we've ended up re-implementing this package to support the latest draft of json schema, I'm going to close this PR as stale. The ideas presented here are still very exciting, however. |
As a continuation to PR #54, I attempted to see what would it take to implement a type system. It turned out not bad. The patch implements json type system, that maps any possible Go type to json type:
null
,boolean
,integer
,number
,string
,object
,array
. It allows validators not to care about specific Go type and their differences. For example, a validator can type assertobject
and read data without needing to differentiate betweenmap
andstruct
.The most important part of the patch is a new file
types.go
. The rest is primarily patching existing validators. The new code needs testing, which I'll do if you consider merging.I benchmarked the current master and this branch using benchmarks from PR #56. It has a significant performance degradation running
type
validator. I haven't checked exactly where most of the time is spent, but is worth to see if we can optimize it.