carterkozak opened a new pull request #555:
URL: https://github.com/apache/logging-log4j2/pull/555


   Previously the entire input string was written to the output
   buffer, then small sections were deleted or replaced within that
   string. This meant that for each section that was abbreviated,
   nearly all following characters from subsequent sections would
   be migrated, resulting in O(n^2) performance.
   
   Now we read from the existing input String, and write sections
   to the output buffer piece-by-piece. For small strings this may
   result in more pointer-hopping (may cost ~tens of nanoseconds) while
   larger values with many abbreviated sections are substantially
   less expensive. I would expect large "enterprise-grade" class
   names to perform better than previously.
   
   Note that the new approach may result in multiple StringBuilder
   resize operations in the worst case, where previously writing
   the original string to the output would have caused it to grow
   all at once. In most cases we attempt to initialize builders
   with a reasonable size, so I opted not to add an `ensureCapacity`
   given the estimated size may be substantially larger than we need.
   
   Benchmarks with this change:
   ```
   NamePatternConverterBenchmark.benchNamePatternConverter  
org.bogus.hokus.pokus.org.bogus.hokus.pokus.org.bogus.hokus.pokus.RetroEncabulatorFactorySingleton
  avgt    3  202.992 ±  1.584  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                  org.bogus.hokus.pokus.Clazz1  
avgt    3   76.517 ±  2.979  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                  com.bogus.hokus.pokus.Clazz2  
avgt    3   75.369 ±  3.217  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                edu.bogus.hokus.pokus.a.Clazz3  
avgt    3   97.546 ± 12.164  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                       de.bogus.hokus.b.Clazz4  
avgt    3   82.240 ± 14.489  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                             jp.bogus.c.Clazz5  
avgt    3   65.274 ±  3.938  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                                   cn.d.Clazz6  
avgt    3   50.239 ±  0.456  ns/op
   ```
   
   Previous results:
   ```
   NamePatternConverterBenchmark.benchNamePatternConverter  
org.bogus.hokus.pokus.org.bogus.hokus.pokus.org.bogus.hokus.pokus.RetroEncabulatorFactorySingleton
  avgt    3  209.477 ± 62.262  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                  org.bogus.hokus.pokus.Clazz1  
avgt    3   76.083 ±  8.123  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                  com.bogus.hokus.pokus.Clazz2  
avgt    3   76.109 ± 19.293  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                edu.bogus.hokus.pokus.a.Clazz3  
avgt    3   91.913 ± 46.029  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                       de.bogus.hokus.b.Clazz4  
avgt    3   74.703 ± 28.086  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                             jp.bogus.c.Clazz5  
avgt    3   59.788 ±  7.298  ns/op
   NamePatternConverterBenchmark.benchNamePatternConverter                      
                                                                   cn.d.Clazz6  
avgt    3   41.092 ± 19.660  ns/op
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to