-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix a performance issue with dependent params #2127
Conversation
d0d4d11
to
1e6555f
Compare
Generated by 🚫 danger |
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.
This makes sense. Let's beef up UPGRADING to explain in which case it might not work?
UPGRADING.md
Outdated
#### Dependent params | ||
|
||
If you use [dependent params](https://github.com/ruby-grape/grape#dependent-parameters) with | ||
`Grape::Extensions::Hash::ParamBuilder`, make sure a parameter to be dependent on is set as a Symbol |
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.
Explain what won't work? In this case a String
? Also add a period at the end of the sentence or maybe a before/after section?
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.
Also add a period at the end of the sentence or maybe a before/after section?
I am not sure what you mean here 😊 Could you explain?
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.
a Symbol. (it's a full sentence, just missing a period)
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.
Regarding before/after, you're saying make sure it's a Symbol. What happens if it's not? Explain that.
3f52bb7
to
ffcb7dd
Compare
Fixes #2100 The reason was in `ActiveSupport::HashWithIndifferentAccess`, it is super expensive. When users use a `Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder` or `Grape::Extensions::Hashie::Mash::ParamBuilder` parameter builder there is no change. However, users who use `Grape::Extensions::Hash::ParamBuilder` must make sure a parameter to be dependent on must be a symbol. given :matrix do # block here end Benchmark after this fix: Warming up -------------------------------------- Given 1.000 i/100ms Simple 1.000 i/100ms Calculating ------------------------------------- Given 0.804 (± 0.0%) i/s - 49.000 in 61.186831s Simple 0.855 (± 0.0%) i/s - 52.000 in 60.926097s Comparison: Simple: 0.9 i/s Given: 0.8 i/s - 1.06x slower
ffcb7dd
to
affd474
Compare
@dblock please, have a look again. thanks. |
|
||
If you use [dependent params](https://github.com/ruby-grape/grape#dependent-parameters) with | ||
`Grape::Extensions::Hash::ParamBuilder`, make sure a parameter to be dependent on is set as a Symbol. | ||
If a String is given, a parameter that other parameters depend on won't be found even if it is present. |
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.
So is this a bug? Should we also fix this (in another PR)?
Fixes #2100
The reason was in
ActiveSupport::HashWithIndifferentAccess
, it is super expensive.When users use a
Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder
orGrape::Extensions::Hashie::Mash::ParamBuilder
parameter builder there is no change. However, users who useGrape::Extensions::Hash::ParamBuilder
must make sure a parameter to be dependent on must be a symbol.Benchmark after this fix: