Vincent, I think the overhead of one object creation is negligible in this case. If you log something, then you have:
1) Object creation. 2) Function call to logger. 3) IO operation (write the log entry). Of these three, number 3 is the overwhelmingly slowest operation. If you have your log statements inside your innermost loops, the consider wrapping them in a: if (LOGGING) { ... } where LOGGING is a static final boolean variable. I read somewhere that this will have the same effect as conditional compilation. If you do not have log statements inside your innermost loops, the loop itself probably overwhelms the performance penalty of a maybe-log. Then again, if you do log something, and it involves disk access, it will overwhelm most non-I/O bound operations. In short - if you get performance problems, your problem is not the extra wrapper object, it is the fact that you are logging too much. /LS > -----Original Message----- > From: Vincent Massol [mailto:[EMAIL PROTECTED] > Sent: den 30 november 2001 10:16 > To: avalon-dev@jakarta.apache.org > Subject: Loggers, final classes and performance > > > Hi, > > I need your expert advice here. The Log4JLogger class is declared > as a final > class. In my code, I use : > > Logger logger = new Log4JLogger( > Category.getInstance(targetName)); > > This is used in a generic method that is called to automatically > log entries > and exits of methods, so it is executed every time there is a log > to be made > for an entry/exit. It is thus called very often. > > I'd like to know if it has any performance issue. More specifically, I'd > like to know if the final keyword helps for performance (as it does for > final methods which are inlined) : I guess that even with the > final keyword, > there is always a new object instanciated in memory ... > > So, I also guess that simply writing : > > Category category = Category.getInstance(targetName); > > would be more performant ? > > Another solution would be to have a hashmap of all loggers and > check in the > hashmap whether the logger for a given targetName already exist > and then use > that logger if it does. However, the additional work (putting the > instances > in the hash, possibly with synchronisation (argh!), then doing an "if" and > then fetching the logger from the hash) might overall be more costly that > instanciating a new object. > > What do you think ? Any idea ? > Thanks > -Vincent > > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>