Commit aa53fd0
committed
Slightly speed up the contains keyword.
Saves some unnecessary repeated validator re-creation while validating
arrays.
In a quick benchmark (added here) and on my local machine (an M2 Mini)
this goes from:
```
baseline: Mean +- std dev: 3.55 us +- 0.04 us
beginning: Mean +- std dev: 3.37 ms +- 0.02 ms
middle: Mean +- std dev: 3.37 ms +- 0.03 ms
end: Mean +- std dev: 3.36 ms +- 0.02 ms
invalid: Mean +- std dev: 3.40 ms +- 0.02 ms
```
to:
```
baseline: Mean +- std dev: 4.27 us +- 0.05 us
beginning: Mean +- std dev: 2.65 ms +- 0.01 ms
middle: Mean +- std dev: 2.66 ms +- 0.02 ms
end: Mean +- std dev: 2.67 ms +- 0.02 ms
invalid: Mean +- std dev: 2.70 ms +- 0.02 ms
```
on the included example (synthetic of course, but not ridiculously so).
(The lack of difference in timing for how far into the array we get
before finding a match seems interesting but probably requires a
benchmark with a more interesting subschema we're matching on).1 parent c9e2029 commit aa53fd0
3 files changed
+36
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
2 | 7 | | |
3 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
98 | 100 | | |
99 | | - | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments