On Saturday 31 Mar 2012 04:03:10 Zlatin Balevsky wrote: > >> > >> In 'log.info("Random message: %s", obj.toString())' evaluating > >> 'obj.toString()' was what caused issues, not recycling it, or so I believe > >> to remember. > > > > You don't need to call obj.toString() before calling log() - just pass the > > object itself. Then the only overheads are: > > 1) Calling the function, including passing the arguments - which hopefully > > will be optimised to be on some stack (but the code might not have been > > JITted yet). > > 2) Looking up whether it needs to be logged. > > > > 3) Autoboxing because you cannot pass a primitive if the argument is > Object without creating a <? extends Number>. Small ranges of > Char/Short/Integer/Long values are cached, anything outside those will > end up creating garbage if the shouldLog predicate evaluate true even > once.
Will it still autobox them if they are on the stack, and never used? > > ... but you could get around this problem by adding many log functions > with different signatures that take primitives. The burden then falls > on the programmer to find the appropriate function at each call site. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: <https://emu.freenetproject.org/pipermail/devl/attachments/20120402/cb0aaa06/attachment.pgp>