>>
>> 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.

... 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.
_______________________________________________
Devl mailing list
Devl@freenetproject.org
https://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to