News for hackers. Stuff that matters.
Re:Do not log by stickfigure on Saturday March 14, 2020 @09:58AM (#22575298)
At least in Javaland, the "should I log" condition test for most logging libraries takes nanoseconds. Unless you're in an extremely tight loop, performance is fine.
Re:Do not log by benschulz on Saturday March 14, 2020 @10:48AM (#22575670)
If it was absolutely necessary you could even have the JIT remove the code and then de-optimize when you enable tracing[1]. That would solve the tight-loop issue..

[1]: https://community.oracle.com/blogs/forax/2011/12/17/jsr-292-...

Re:Do not log by pkolaczk on Saturday March 14, 2020 @03:33PM (#22578003)
Correct, in simple cases it can do it, but you need to be very careful with computing the arguments for the logging call. Java has no lazy evaluation of args nor macros, so if you accidentally concat strings there or do something expensive, it is likely JVM won't optimize these out. That's why typically you want to guard your logging calls on the hot path with an if condition.