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

JSON generation for largish data structures v. slow under 1.7 (JDK 1.6)

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.7.0.pre1, JRuby 1.7.0.pre2
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: None
    • Labels:
    • Environment:
      jruby 1.7.0.preview2.dev (ruby-1.9.3-p203) (2012-07-29 b9e669b) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
    • Number of attachments :
      1

      Description

      [ See benchmark code and results at https://gist.github.com/3213716 ]

      Under jruby-head and 1.7.0pre1, json generation from non-trivially-sized hashes using the json gem is ridiculously slow (0.3 seconds under 1.6, 130 second under 1.7).

      The slowdown is less severe using "require json/pure" ("only" a factor of 100)

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        It looks like it may have something to do with running in 1.9 mode...something that's considerably more expensive. My money's on encoding/transcoding.

        system ~/projects/jruby $ jruby -rubygems --1.8 tmp/json_generate.rb 
        jruby 1.7.0.preview2.dev (ruby-1.8.7-p357) (2012-07-31 f3cc223) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_33) [darwin-x86_64-java]
              user     system      total        real
          0.420000   0.000000   0.420000 (  0.182000)
        
        system ~/projects/jruby $ jruby -rubygems --1.9 tmp/json_generate.rb 
        jruby 1.7.0.preview2.dev (ruby-1.9.3-p203) (2012-07-31 f3cc223) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_33) [darwin-x86_64-java]
               user     system      total        real
         156.890000   2.990000 159.880000 (156.208000)
        
        Show
        Charles Oliver Nutter added a comment - It looks like it may have something to do with running in 1.9 mode...something that's considerably more expensive. My money's on encoding/transcoding. system ~/projects/jruby $ jruby -rubygems --1.8 tmp/json_generate.rb jruby 1.7.0.preview2.dev (ruby-1.8.7-p357) (2012-07-31 f3cc223) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_33) [darwin-x86_64-java] user system total real 0.420000 0.000000 0.420000 ( 0.182000) system ~/projects/jruby $ jruby -rubygems --1.9 tmp/json_generate.rb jruby 1.7.0.preview2.dev (ruby-1.9.3-p203) (2012-07-31 f3cc223) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_33) [darwin-x86_64-java] user system total real 156.890000 2.990000 159.880000 (156.208000)
        Hide
        Charles Oliver Nutter added a comment -

        A sampling profile shows the same elements being slow as for other reports...specifically, character set negotiation during transcoding:

         14.0%   416  +     0    sun.nio.cs.ext.ExtendedCharsets.<init>
        ...
         27.6%   791  +    27    java.util.TreeMap.put
         26.0%   770  +     0    sun.nio.cs.AbstractCharsetProvider.charset
        
        Show
        Charles Oliver Nutter added a comment - A sampling profile shows the same elements being slow as for other reports...specifically, character set negotiation during transcoding: 14.0% 416 + 0 sun.nio.cs.ext.ExtendedCharsets.<init> ... 27.6% 791 + 27 java.util.TreeMap.put 26.0% 770 + 0 sun.nio.cs.AbstractCharsetProvider.charset
        Hide
        Charles Oliver Nutter added a comment -

        This commit will probably resolve the bulk of your perf issues. There's more tuning needed in our transcoding subsystem, but we'll call this particular issue resolved.

        commit a00d2a223def2da87d105252b857c953de69a2e0
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Tue Jul 31 12:28:01 2012 -0500
        
            Fix JRUBY-6802 (and probably JRUBY-6803)
            
            JSON generation for largish data structures v. slow under 1.7 (JDK 1.6)
            Reading thousands of files significantly slower with JRuby 1.7
            
            This isn't a complete fix, but it solves the most egregious perf
            issue.
            
            The transcoding logic in JRuby currently does Charset.forName()
            lookups repeatedly to get the proper Java Charset for a given
            jcodings Encoding. Unfortunately, the "ASCII-8BIT" name used by
            Ruby (and jcodings) does not map to a Charset, resulting in
            every transcoding operation triggering an exception from forName.
            Short-circuiting this logic explicitly for ASCII-8BIT avoids that
            issue.
            
            We're aware that there are other encodings that will also trigger
            exceptions, and that we're repeatedly looking up the same Charsets
            over and over. We will fix that in separate commits. Because the
            bulk of the performance issues in these two bugs are fixed by this
            patch, I'm going to call them resolved.
        
        :100644 100644 6183077... 5d626b2... M	src/org/jruby/util/CharsetTranscoder.java
        
        Show
        Charles Oliver Nutter added a comment - This commit will probably resolve the bulk of your perf issues. There's more tuning needed in our transcoding subsystem, but we'll call this particular issue resolved. commit a00d2a223def2da87d105252b857c953de69a2e0 Author: Charles Oliver Nutter <headius@headius.com> Date: Tue Jul 31 12:28:01 2012 -0500 Fix JRUBY-6802 (and probably JRUBY-6803) JSON generation for largish data structures v. slow under 1.7 (JDK 1.6) Reading thousands of files significantly slower with JRuby 1.7 This isn't a complete fix, but it solves the most egregious perf issue. The transcoding logic in JRuby currently does Charset.forName() lookups repeatedly to get the proper Java Charset for a given jcodings Encoding. Unfortunately, the "ASCII-8BIT" name used by Ruby (and jcodings) does not map to a Charset, resulting in every transcoding operation triggering an exception from forName. Short-circuiting this logic explicitly for ASCII-8BIT avoids that issue. We're aware that there are other encodings that will also trigger exceptions, and that we're repeatedly looking up the same Charsets over and over. We will fix that in separate commits. Because the bulk of the performance issues in these two bugs are fixed by this patch, I'm going to call them resolved. :100644 100644 6183077... 5d626b2... M src/org/jruby/util/CharsetTranscoder.java

          People

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

            Dates

            • Created:
              Updated:
              Resolved: