Skip to content
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

Cache file reads #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Cache file reads #98

wants to merge 1 commit into from

Conversation

dizer
Copy link

@dizer dizer commented Jun 12, 2019

Now every match_json_schema call reloads the whole schema from disk. It may slow when there are many files (~1 second for each test example in our case).

This PR caches document store on the class level.

lib/json_matchers/matcher.rb Outdated Show resolved Hide resolved
lib/json_matchers/matcher.rb Outdated Show resolved Hide resolved
lib/json_matchers/matcher.rb Outdated Show resolved Hide resolved
lib/json_matchers/matcher.rb Outdated Show resolved Hide resolved
@@ -15,6 +15,7 @@

config.around do |example|
ensure_fixtures("spec", "fixtures", "schemas") do
JsonMatchers::Matcher.document_store = nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is it necessary to throw away our cache in each of the project's test suites?

Could you elaborate more on those details in the commit message?

Copy link
Author

Choose a reason for hiding this comment

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

It clears shared state (cache) between test cases

@seanpdoyle
Copy link
Collaborator

Could you provide more details in the commit message?

I'm very interested to learn more about the implications of these changes in your test suite, is that something that you've measured?

@dizer
Copy link
Author

dizer commented Jul 1, 2019

Hi @seanpdoyle

You can try benchmarks at https://github.com/dizer/json_matchers_cache

Original, single document, 1000 tries:
0.99 sec
Original, linked document, 1000 tries:
5.68 sec

Patched, single document, 1000 tries:
0.52 sec
Patched, linked document, 1000 tries:
0.92 sec

For our requests tests suite (124 JSON schema files, 5047 lines) it saved about a minute.

@kzaitsev
Copy link

kzaitsev commented Feb 25, 2021

Hi @seanpdoyle, any chance to get it merged? This feature is very helpful, with this patched version our specs working faster (3-4 minutes vs 20 minutes).

If you don't have time to resolve conflicts let me know, I'll create a new PR.

@artofhuman
Copy link

Hi @seanpdoyle. We also have same issues with speed in our tests after upgrade from 0.9 to 0.11 version. Could you merge this patch?

@thai-eh
Copy link

thai-eh commented Jun 24, 2024

@seanpdoyle Please help take a look at this when you have a chance, thanks!

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.

5 participants