You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
We don't need to use captured groups using ruby methods for matching content against regex or splitting. Using them will affect badly on performance of RE.
Exception is the back references in regex, so for sure we need regexp parser for that.
# bad
'str'.match? /(?<X>s)/
# => true
# bad
'str'.match? /(s)/
# => true
# good
'str'.match? /s/
# => true
Describe the solution you'd like
Add a cop to detect this problem, maybe also autofix ?
During the splitting we also don't check/fetch groups so it can be more beneficial to omit groups
It's not only regexp optimization because it is bound with ruby method using this regexps
require 'benchmark/ips'
regexp1 = %r{\s([\&/]\s)?}
regexp2 = %r{\s(?:[\&/]\s)?}
string = 'HR / People & People Ops'
Benchmark.ips do |x|
x.report("with group") do
string.split regexp1
end
x.report("without capture") do
string.split regexp2
end
x.compare!
end
Calculating -------------------------------------
with group 495.069k (± 2.7%) i/s - 2.496M in 5.045809s
without capture 555.395k (± 1.4%) i/s - 2.797M in 5.037793s
Comparison:
without capture: 555395.2 i/s
with group: 495069.1 i/s - 1.12x slower
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
Is your feature request related to a problem? Please describe.
We don't need to use captured groups using ruby methods for matching content against regex or splitting. Using them will affect badly on performance of RE.
Exception is the back references in regex, so for sure we need regexp parser for that.
Describe the solution you'd like
Add a cop to detect this problem, maybe also autofix ?
Describe alternatives you've considered
It can be optimized on ruby regex library without cop ? https://github.com/k-takata/Onigmo
Additional context
During the splitting we also don't check/fetch groups so it can be more beneficial to omit groups
It's not only regexp optimization because it is bound with ruby method using this regexps
The text was updated successfully, but these errors were encountered: