You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2015/10/05 13:42:26 UTC

[jira] [Created] (LOG4J2-1151) Performance improvement: backport fast Java 8 String to byte[] encoder to AbstractStringLayout

Remko Popma created LOG4J2-1151:
-----------------------------------

             Summary: Performance improvement: backport fast Java 8 String to byte[] encoder to AbstractStringLayout
                 Key: LOG4J2-1151
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1151
             Project: Log4j 2
          Issue Type: Improvement
          Components: Layouts
    Affects Versions: 2.4
            Reporter: Remko Popma
            Assignee: Remko Popma
             Fix For: 2.4.1


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:
{quote}
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)
{quote}

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)*

{code}
Benchmark                                                              Mode  Samples    Score    Error  Units
o.a.l.l.p.j.StringEncodingBenchmark.customIso8859_1                  sample   156848   94.014 ±  2.362  ns/op
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
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
o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesStringShiftJIS     sample   125817  354.961 ±  4.072  ns/op
{code}


*jdk 1.7.0_55 (64 bit Hotspot)*

{code}
Benchmark                                                              Mode  Samples     Score    Error  Units
o.a.l.l.p.j.StringEncodingBenchmark.customIso8859_1                  sample   148456    93.248 ±  2.193  ns/op
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
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
o.a.l.l.p.j.StringEncodingBenchmark.stringGetBytesStringShiftJIS     sample   114733   808.315 ± 27.177  ns/op
{code}




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org