-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Deprecate passing string to define callback. #22598
Conversation
r? @pixeltrix (@rails-bot has picked a reviewer for you, use r? to override) |
ref #22460 |
👍 @yui-knk 😄 As part of this commit, I think you should also remove this documentation. |
@@ -48,7 +48,8 @@ def _normalize_callback_options(options) | |||
|
|||
def _normalize_callback_option(options, from, to) # :nodoc: | |||
if from = options[from] | |||
from = Array(from).map {|o| "action_name == '#{o}'"}.join(" || ") | |||
_from = Array(from).map(&:to_s) |
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.
Maybe we should create a Set so the performance of include?
is better?
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.
Hm, looks like creating Sets is too slow. Here's a benchmark. With an Array of 10 elements, creating a Set and then calling #include? is 5x slower than creating an Array and calling #include?
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.
Yes, creating sets is slow but we are creating only once and we are calling include on every request so it may be worth using Set here.
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.
Per the size of the Array it will not matter.
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.
@nateberkopec Thanks for your help
$ ruby creating_set.rb
Calculating -------------------------------------
set include 45.093k i/100ms
array include 15.519k i/100ms
-------------------------------------------------
set include 713.458k (± 5.0%) i/s - 3.562M
array include 182.015k (± 4.3%) i/s - 915.621k
Comparison:
set include: 713457.8 i/s
array include: 182014.8 i/s - 3.92x slower
1547683
to
21f4017
Compare
@rafaelfranca I updatd 😍 |
Deprecate passing string to define callback.
No description provided.