rgoers commented on a change in pull request #289: LOG4J2-2644 - Improve performance of getting location info URL: https://github.com/apache/logging-log4j2/pull/289#discussion_r299080106
########## File path: log4j-api-java9/src/main/java/org/apache/logging/log4j/util/StackLocator.java ########## @@ -72,15 +75,38 @@ private StackLocator() { } public StackTraceElement calcLocation(final String fqcnOfLogger) { - return stackWalker.walk( - s -> s.dropWhile(f -> !f.getClassName().equals(fqcnOfLogger)) // drop the top frames until we reach the logger - .dropWhile(f -> f.getClassName().equals(fqcnOfLogger)) // drop the logger frames - .findFirst()) - .get() - .toStackTraceElement(); + return walker.walk(LOCATOR.get().setFqcn(fqcnOfLogger)).toStackTraceElement(); } public StackTraceElement getStackTraceElement(final int depth) { return stackWalker.walk(s -> s.skip(depth).findFirst()).get().toStackTraceElement(); } + + static final class FqcnCallerLocator implements Function<Stream<StackWalker.StackFrame>, StackWalker.StackFrame> { + + private String fqcn; + + public FqcnCallerLocator setFqcn(String fqcn) { + this.fqcn = fqcn; + return this; + } + + @Override + public StackWalker.StackFrame apply(Stream<StackWalker.StackFrame> stackFrameStream) { + boolean foundFqcn = false; + Object[] frames = stackFrameStream.toArray(); Review comment: I don't know but I suspect not. The test I am running has a stack size of 35 entries. My understanding is the StackFrames are optimized for when you access less than 8., but it might just be grabbing them in batches of 8. I haven't checked that. I do know that the stream logic is adding considerable overhead. I suspect this would be even faster if there were methods that could do this inside of StackWalker without having to create the Stream. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services