Closed breunigs closed 6 years ago
Ah, tested only on Ruby 2.4.
Thanks @breunigs! Even without a performance gain, this still seems like a cleaner/better way to implement this.
(I suspect that optimizing this library will be a very deep rabbit hole BTW. It's really not written with speed in mind at all.)
Released as 0.17.1.
Don't make yourself so small. For the same workload json_schema takes ~11seconds, whereas json-schema takes ~3m05s. I'm also contend once it's "fast enough for our task", so I won't overdo it. The bigger issue is that due to the recursive approach flamegraphs don't show any obvious culprits to investigate. If time allows, I'll dig a bit deeper, but no promises.
For the same workload json_schema takes ~11seconds, whereas json-schema takes ~3m05s. I'm also contend once it's "fast enough for our task", so I won't overdo it.
That's pretty cool. I'm honestly quite surprised that json_schema
is faster, let along the stark difference! Thanks
The bigger issue is that due to the recursive approach flamegraphs don't show any obvious culprits to investigate. If time allows, I'll dig a bit deeper, but no promises.
I've always suspected that the reference expansion code could be made much more efficient, but the good news is that only needs to be run once on the initial schema expansion and things should be quick from there.
Sounds good though. Let me know if you end up making any interesting improvements.
On a not-too-complex schema, validating a 15 MB JSON file, the
flat_map
saves roughly 3% processing time.Total time (seconds) for 40 validation runs of the same file. Loading the schema and parsing the file were not part of the test run: