Re: About performance

2017-03-30 Thread Matt Sicker
Look at the source code for Thread.getStackTrace(). When this == currentThread(), it calls new Exception().getStackTrace(). Less indirection to just do it directly. ;) On 30 March 2017 at 10:16, Ralph Goers wrote: > I should note that in Java 9 getting the location

Re: About performance

2017-03-30 Thread Ralph Goers
I should note that in Java 9 getting the location information will be much faster. Ralph > On Mar 30, 2017, at 7:44 AM, Pietro Galassi wrote: > > Perfect. > > So using a method that will add location information on demand is the best > choice. This will let remove

Re: About performance

2017-03-30 Thread Pietro Galassi
Perfect. So using a method that will add location information on demand is the best choice. This will let remove %M or the specific method finding logic whenever it's not necessary. Regards. On Thu, Mar 30, 2017 at 4:36 PM, Remko Popma wrote: > > > On Mar 30, 2017, at

Re: About performance

2017-03-30 Thread Remko Popma
> On Mar 30, 2017, at 21:51, Pietro Galassi wrote: > > Thanks a lot! > > So: > > - for class name better to use %c with the LogManager.getLogger(this.class) > instead of the calculation i do ? Yes. > > - for method name avoid %M and use new

Re: About performance

2017-03-30 Thread Pietro Galassi
Thanks a lot! So: - for class name better to use %c with the LogManager.getLogger(this.class) instead of the calculation i do ? - for method name avoid %M and use new Throwable().getStackTrace instead Thread.currentThread().getStackTrace() to get better performance ? Regards On Thu, Mar 30,

Re: About performance

2017-03-30 Thread Remko Popma
Sent from my iPhone > On Mar 30, 2017, at 16:24, Pietro Galassi wrote: > > So, > > using such code like this: > > LogManager.getLogger(this.class); will let the code be fast ? Yes. > > > and it's faster than the code i published ? Yes. The point of my answer was

Re: About performance

2017-03-30 Thread Pietro Galassi
So, using such code like this: LogManager.getLogger(this.class); will let the code be fast ? and it's faster than the code i published ? Also why new Throwable().getStackTrace is faster than Thread.currentThread().getStackTrace(). ? Does the new in Throwable can give performance issue ?

Re: About performance

2017-03-29 Thread Remko Popma
Pietro, The performance impact of logging location information is massive. See https://logging.apache.org/log4j/2.x/performance.html#asyncLoggingWithLocation You can increase logging speed by ~80x by not logging location information. If you follow the conventions that each class has its own

Re: About performance

2017-03-29 Thread Ralph Goers
What Java version are you using? Why do you think your code is going to perform better than what Log4j is doing? The fastest way to get the caller information is to use Java 9’s StackWalker.getCallerClass() method which only takes a couple of milliseconds. But doing that might actually make

Re: About performance

2017-03-29 Thread Matt Sicker
The %m%n pattern is just the formatted message and a new line. The %M pattern is for method names. And the current algorithm for finding it is about the same: <