carterkozak 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_r299084747
########## 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 see, I didn't realize it was chunked internally, that's great! It's unfortunate that streams don't JIT very well compared to standard loops/iterators, the array sounds like the way to go if it performs better than the fluent stream approach. ---------------------------------------------------------------- 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