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

Optimize PredicateRegistry for Ruby 2.7+ #420

Merged
merged 1 commit into from
Mar 27, 2021

Conversation

casperisfine
Copy link

2.7 introduced UnboundMethod#bind_call which is much faster than
doing Method.bind(receiver).call.

And even on older rubies caching Kernel.instance_method(:respond_to?)
in a constant will save quite a lot of extra costly allocations.

@casperisfine casperisfine requested a review from solnic as a code owner March 26, 2021 11:02
@flash-gordon
Copy link
Member

@casperisfine could you show that this optimization makes a difference for a typical dry-types usage? I don't think the registry is queried in "runtime" (when types are already defined) but I might be wrong.

@casperisfine
Copy link
Author

I don't think the registry is queried in "runtime"

I should have specified that I found this in our boot profiling reports. Boot time is important to us so we have daily profiling of it.

2.7 introduced `UnboundMethod#bind_call` which is much faster than
doing `Method.bind(receiver).call`.

And even on older rubies caching `Kernel.instance_method(:respond_to?)`
in a constant will save quite a lot of extra costly allocations.
@flash-gordon
Copy link
Member

Ok, fair enough. I think we could a cache or something, this could be even faster but it'll require benchmarking. I'll merge it as it is.

@flash-gordon flash-gordon merged commit 0b12c8f into dry-rb:master Mar 27, 2021
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.

3 participants