thomasmueller commented on code in PR #813: URL: https://github.com/apache/jackrabbit-oak/pull/813#discussion_r1064511135
########## oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java: ########## @@ -78,6 +79,23 @@ public class SessionDelegate { static final Logger readOperationLogger = LoggerFactory.getLogger("org.apache.jackrabbit.oak.jcr.operations.reads"); static final Logger writeOperationLogger = LoggerFactory.getLogger("org.apache.jackrabbit.oak.jcr.operations.writes"); + // the bitmask used for trace level logging + // we use a bitmask instead of a counter to avoid the slow modulo operation: + // https://stackoverflow.com/questions/27977834/why-is-modulus-operator-slow + // so we use "if ((counter & LOG_TRACE_BIT_MASK) == 0) log(...)" + // instead of the slower "if ((counter % LOG_TRACE) == 0) log(...)" + // that means the values need to be some power of two, minus one + // log every 128th call by default + private static final long LOG_TRACE_BIT_MASK = Long.getLong( + "org.apache.jackrabbit.oak.jcr.operations.bitMask", + 128L - 1); + // log a stack trace every ~1 million calls by default + private static final long LOG_TRACE_STACK_BIT_MASK = Long.getLong( + "org.apache.jackrabbit.oak.jcr.operations.stack.bitMask", + 1024L * 1024 - 1); + // the counter used for logging + private static final AtomicLong LOG_COUNTER = new AtomicLong(); Review Comment: Yes, it will continue to work. Modulo, on the other hand, behaves in a slightly weird way for negative numbers: you get negative reminders. But checking for (x % y) == 0 would still work fine. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org