Ok, Thanks Leo. I agree with you but the operations are additive (and not in parallel), so I'm trying to squeeze the maximum of log information for the same price :). Logging will stay enabled during production but we want to be able to turn it off/on/change level dynamically, so the if (LOGGING) would not work. The "new" will instanciate about 10K logger objects per second and I was just wondering if it would make any difference (especially by triggering the gc more frequently maybe).
But I agree this is probably negligible compared to other stuff. Thanks -Vincent ----- Original Message ----- From: "Leo Sutic" <[EMAIL PROTECTED]> To: "Avalon Developers List" <avalon-dev@jakarta.apache.org>; "Vincent Massol" <[EMAIL PROTECTED]> Sent: Friday, November 30, 2001 1:12 PM Subject: RE: Loggers, final classes and performance > 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]>