JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6915

Improve performance of the Equals operator in the RubyComparable class for objects of different types.

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.7
    • Fix Version/s: JRuby 1.7.0.RC2
    • Component/s: Performance
    • Labels:
      None
    • Environment:
      Ubuntu, Java 1.6
    • Number of attachments :
      0

      Description

      Hi,

      I discovered one problem with performance of the equals operator in the RubyComparable class.

      To have a picture what I have , please check a performance of the following commands:

      require 'benchmark'
      b = Time.now
      print Benchmark.measure { 10000.times { Time.now == '' } }.inspect + "\n"
      print Benchmark.measure { 10000.times { Time.now == b } }.inspect + "\n"
      

      As you see, when objects of different types are being compared, performance is way lower.

      After running following command:

      jruby -d -Xbacktrace.style=raw -J-Djruby.log.backtraces=true -e'print Time.now == ""'
      

      It turned out, that there are is some exception being thrown, and, but it doesn't show up in the ruby console, as e.g. for the '>' or '>=' operators.

      After I looked into the code, I have a feeling, that it's not needed to raise the ArgumentError, since it's not being shown in the ruby console.
      Currently, this exception is being caught, and the returnValueOnError variable is being returned. Can this behavior be changed? I think the returnValueOnError value can be returned immediately, in case when the comparison value is nil.

      Is there any other reason (which I could have missed) for raising the exception is needed for this operator?

      Please see my pull request with possible solution for this problem: -FIXME-
      After switching to the code with my fix, please run again the performance tests listed above. It should do the comparison much faster.

      Best,
      Kamil.

        Activity

        Hide
        Kamil Bednarz added a comment -

        I see I cannot edit the ticket's description, so here is the mentioned pull request:
        https://github.com/jruby/jruby/pull/330

        Show
        Kamil Bednarz added a comment - I see I cannot edit the ticket's description, so here is the mentioned pull request: https://github.com/jruby/jruby/pull/330
        Hide
        Charles Oliver Nutter added a comment -

        Great find, thank you! We probably should audit JRuby at some point to look for useless exception raising like this.

        Show
        Charles Oliver Nutter added a comment - Great find, thank you! We probably should audit JRuby at some point to look for useless exception raising like this.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Kamil Bednarz
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: