Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1151

Performance improvement: backport fast Java 8 ISO-8859-1 String to byte[] encoder to AbstractStringLayout

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.4
    • 2.4.1
    • Layouts
    • None

    Description

      Java 8 made large improvements to String encoding performance for all character sets. Especially for the ISO8859_1 encoding, Java 8 introduced logic that simply casts each char in the array to a byte, giving a huge performance increase.

      This ticket proposes to backport that logic into AbstractStringLayout to get the same performance in Java 7.

      Focussing on the results for ISO8859_1:

      Java 7 String.getBytes(): ~200-300 ns/op
      Java 8 String.getBytes(): ~70-80 ns/op
      Custom logic: ~90 ns/op (on both Java 7 and 8)

      Benchmarks below are with a representative message string of 100 characters, on 64 bit Windows 10, Dual Intel Core i5-3317U @1.70GHz with hyperthreading on (4 cores).

      jdk 1.8.0_60 (64 bit Hotspot)

      Benchmark                                                              Mode  Samples    Score    Error  Units
      o.a.l.l.p.j.StringEncodingBenchmark.customIso8859_1                  sample   156848   94.014 ±  2.362  ns/op <- custom
      o.a.l.l.p.j.StringEncodingBenchmark.encoderIso8859_1                 sample   103773  859.529 ± 27.461  ns/op
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytes                   sample   125785  363.129 ± 17.674  ns/op
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesCharSet88591       sample   117191   72.606 ±  2.771  ns/op <- variation 1
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesCharSetShiftJIS    sample   102914  452.721 ± 21.274  ns/op
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesString88591        sample   181547   79.653 ±  1.735  ns/op <- variation 2
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesStringShiftJIS     sample   125817  354.961 ±  4.072  ns/op
      

      jdk 1.7.0_55 (64 bit Hotspot)

      Benchmark                                                              Mode  Samples     Score    Error  Units
      o.a.l.l.p.j.StringEncodingBenchmark.customIso8859_1                  sample   148456    93.248 ±  2.193  ns/op <- custom
      o.a.l.l.p.j.StringEncodingBenchmark.encoderIso8859_1                 sample   176198   516.731 ± 24.054  ns/op
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytes                   sample   121660   731.530 ± 27.116  ns/op
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesCharSet88591       sample    99636   234.709 ±  3.234  ns/op <- variation 1
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesCharSetShiftJIS    sample   125754  1401.008 ± 25.385  ns/op
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesString88591        sample   147124   316.411 ± 21.454  ns/op <- variation 2
      o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesStringShiftJIS     sample   114733   808.315 ± 27.177  ns/op
      

      Attachments

        Issue Links

          Activity

            People

              rpopma Remko Popma
              rpopma Remko Popma
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: