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_r299086416
########## 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: Ultimately I will have to create a separate project at GitHub with JMH benchmarks to show how the variations behave and then open tickets against the JDK to see what can be done if it can be shown that using Streams isn't the most performant way to access stack traces. ---------------------------------------------------------------- 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