Project

General

Custom queries



Profile

Actions

Patch #28940

closed

Use Regexp#match? to reduce allocations of MatchData object

Added by Pavel Rosický almost 7 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Performance
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

since Rails 5.1+ we can use match? on a regex class safely even on older rubies
https://github.com/rails/rails/blob/5-1-stable/activesupport/lib/active_support/core_ext/regexp.rb

but the performance benefit is visible only on ruby 2.4+
https://bugs.ruby-lang.org/issues/8110

require 'benchmark/ips'
Benchmark.ips do |x|
  x.report('match') { /test\d/.match 'test5'.freeze }
  x.report('match?') { /test\d/.match? 'test5'.freeze }
  x.compare!
end

Comparison:
match?:  4493322.3 i/s
match:    926754.9 i/s - 4.85x  slower

rake test is about 5% faster


Files

match.patch (34 KB) match.patch Pavel Rosický, 2018-06-04 01:19
match_adapters.patch (3.23 KB) match_adapters.patch Pavel Rosický, 2018-06-04 02:18
match-adapters-v2.diff (1.97 KB) match-adapters-v2.diff Go MAEDA, 2018-06-04 04:53
match-v2.diff (13.6 KB) match-v2.diff Go MAEDA, 2018-06-04 06:54
match_final.patch (27.7 KB) match_final.patch Pavel Rosický, 2018-06-17 18:14
match_final.patch (28.3 KB) match_final.patch r18001 Pavel Rosický, 2019-03-21 23:01

Related issues

Related to Redmine - Patch #28939: replace regexp with casecmpClosed

Actions
#5

Updated by Go MAEDA almost 7 years ago

  • Related to Patch #28939: replace regexp with casecmp added
#6

Updated by Go MAEDA almost 7 years ago

#7

Updated by Go MAEDA almost 7 years ago

#8

Updated by Go MAEDA almost 7 years ago

  • Target version set to Candidate for next major release
#9

Updated by Go MAEDA almost 7 years ago

  • Target version changed from Candidate for next major release to 4.1.0
#10

Updated by Pavel Rosický almost 7 years ago

#13

Updated by Go MAEDA about 6 years ago

  • Subject changed from reduce allocations to Use Regexp#match? to reduce allocations of MatchData object
  • Assignee set to Go MAEDA
#14

Updated by Go MAEDA about 6 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF