brandur / json_schema

A JSON Schema V4 and Hyperschema V4 parser and validator.
MIT License
230 stars 45 forks source link

Some performance improvements #102

Closed tenderlove closed 5 years ago

tenderlove commented 5 years ago

Hi,

We're using this gem at work (thank you for writing it!), and we're hitting some performance bottlenecks. This PR aims to address some of them. I apologize for not posting a benchmark. We're loading a bunch of schemas on boot in our application, and I'm not sure what of that production data I can make public.

Each commit contains the result of the benchmarks I use against our production data. Before these commits, loading our schemas would take 8.4 seconds and allocate over 30 million objects. These commits reduce it to 4.5 seconds and about 5 million objects.

Of the 5 million remaining objects, this line allocates 3.2 million objects. I tried to cache that string, but it seems like the objects are mutable, so I couldn't get the cache invalidation to work correctly and it broke all the tests 😞.

I will work on getting a benchmark that I can share, but in the mean time I wanted to send these changes.

Thank you!

brandur commented 5 years ago

Thanks Aaron!

Don't worry too much about the benchmarks (unless you're able to contribute one that we could commit and use to measure performance changes and improvements in a broader way). I didn't run any benchmarking when I originally wrote this, so it's easy to imagine there's a lot of room for improvement.

The build is failing because Bundler no longer seems to be working on Ruby 2.0 or 2.1. They're well into their EOL now, so I just dropped them from the build matrix in #103.

brandur commented 5 years ago

Released as 0.20.1.