Bug #8847

opt_regexpmatch2 does not use method caching

Added by Charlie Somerville 8 months ago. Updated 8 months ago.

[ruby-core:56916]
Status:Closed
Priority:Normal
Assignee:Charlie Somerville
Category:-
Target version:-
ruby -v:ruby 2.1.0dev (2013-08-31 trunk 42741) [x86_64-darwin12.4.0] Backport:1.9.3: UNKNOWN, 2.0.0: DONTNEED

Description

The optregexpmatch2 instruction does not use method caching, instead it uses rbfuncall internally.

opt_regexpmatch2 is emitted by the compiler when a literal regexp is on the right hand side of the =~ operator.

This means a full method lookup must be performed every time the receiver of the =~ method call is not a String.

Associated revisions

Revision 42742
Added by Charlie Somerville 8 months ago

  • compile.c (NODEMATCH3): pass CALLINFO to opt_regexpmatch2

  • insns.def (optregexpmatch2): use CALLSIMPLEMETHOD to call =~ if
    the receiver is not a T
    STRING [Bug #8847]

History

#1 Updated by Charlie Somerville 8 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42742.
Charlie, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • compile.c (NODEMATCH3): pass CALLINFO to opt_regexpmatch2

  • insns.def (optregexpmatch2): use CALLSIMPLEMETHOD to call =~ if
    the receiver is not a T
    STRING [Bug #8847]

#2 Updated by Tomoyuki Chikanaga 8 months ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: UNKNOWN, 2.0.0: REQUIRED

Hello, charlisome.

I think this fix should be backported to ruby200.
Could you give me a testcase to cover this fix?
I'd like to confirm the same problem exists in ruby
200 branch.

#3 Updated by Charlie Somerville 8 months ago

nagachika: There's no incorrect behaviour that r42742 fixes - it is merely a performance improvement.

You can use the following benchmark script as a test:

require "benchmark"

puts Benchmark.measure {
  1_000_000.times do
    1 =~ //
    1 =~ //
    1 =~ //
    1 =~ //
    1 =~ //
    1 =~ //
    1 =~ //
    1 =~ //
  end
}

Before my commit, I get this result:

  0.330000   0.000000   0.330000 (  0.332941)

After my commit, I get:

  0.240000   0.000000   0.240000 (  0.241248)

You can probably do something similar to verify your backport is correct.

#4 Updated by Tomoyuki Chikanaga 8 months ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: REQUIRED to 1.9.3: UNKNOWN, 2.0.0: DONTNEED

Ah! I was misunderstanding that this is a bug fix.
Sorry for bother you.

Also available in: Atom PDF