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

Performance improvement when gathering Location Information

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.5
    • Component/s: Core
    • Labels:
    • Environment:

      Java 1.8.0_45 64-bit
      Maven 3.3.1
      Windows 7

      basically any...

      Description

      When gathering Location Information in Log4jLogEvent
      Log4j uses Thread.currentThread().getStackTrace()

      Using (new Throwable()).getStackTrace(); would be more performant especially for larger stacks according to various benchmarks:

      This can easily be verified with a simple JMH Benchmark test.

      What would help in addition is to skip the Log4j Part when iterating over the StackTrace - use i=4 or whatever you may consider as being save enough instead of starting with i=0.

      Basically something like:

      final StackTraceElement[] stackTrace = (new Throwable()).getStackTrace();
      for (int i = 4; i < stackTrace.length; i++) {
      }
      

        Attachments

          Activity

            People

            • Assignee:
              remkop@yahoo.com Remko Popma
              Reporter:
              stefanleo88 Stefan Leonhartsberger
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: