-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Removed data
ivar from JSON::Validator so that multiple validate
call become faster
#465
Conversation
Codecov Report
@@ Coverage Diff @@
## master #465 +/- ##
=======================================
Coverage 89.83% 89.84%
=======================================
Files 74 74
Lines 1555 1556 +1
=======================================
+ Hits 1397 1398 +1
Misses 158 158
Continue to review full report at Codecov.
|
69421f4
to
d6e45e5
Compare
data
ivar from JSON::Validator so that multiple validate
call become faster
@ganmacs thanks for the PR. Could you rebase please to pull in our latest CI changes? |
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.
These changes make sense, loading the schema and the data at the same time does not really makes sense so changing the API to split these two operations is I think a good move.
It reduces a lot of duplicated object creation when you want to apply the same schema but different data ``` schema = .... validator = JSON::Validator.new(schema) validator.validate(data1) validator.validate(data2) validator.validate(data3) ```
d6e45e5
to
d96b036
Compare
Thank you guys for your review. Rebased. |
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.
I missed this, but it looks good to me.
In my environment, I call
JSON::Validator.validate
many times with huge JSON Schema definitions and it takes a lot of time to return value. After some investigations, I found thatJSON::Validator#initialize_schema
inJSON::Validator#initialize
takes most of the time.This patch removes
@data
from instance variables of JSON::Validator so that it can avoid a lot of duplicated object creation. it's really useful and efficient when you want to apply the same schema but different data multiple time.flamegraph
code: https://gist.github.com/ganmacs/29f6217bbd3658d7f1f0010d0cadedd7 (json_schema_test.rb)
Before
After
benchmark
code: https://gist.github.com/ganmacs/29f6217bbd3658d7f1f0010d0cadedd7 (benchmark.rb)