-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize the log formatter #552
optimize the log formatter #552
Conversation
optimize formatting of diagnostic messages
Thanks, there is a lot of impressive work here (or at least it would have taken me a long time to write and debug the string parsing methods). Merging now. |
thank you :). I'll have a look at others possible optimization hotspot, as I'm still wondering the reason of the issue #551 . |
We're having what seems to be a race condition in our tests, which run in parallel in different threads :
I will put up a test case which reproduces the problem |
hi @testinfected , you are totally right: code: public static void main(String[] args) throws Exception {
int p = 20;
CountDownLatch latch = new CountDownLatch(p);
for (int i = 0; i < p;i++) {
new Thread(() -> {
latch.countDown();
try {
latch.await();
XRLog.log(Level.SEVERE, LogMessageId.LogMessageId0Param.CASCADE_IS_ABSOLUTE_CSS_UNKNOWN_GIVEN);
} catch (InterruptedException e) {
}
}).start();
}
} is enough to reproduce the error |
@testinfected I'll open a new issue so we can track it better. |
Thanks @syjer! |
I've opened the issue #646 |
Hi @danfickle , this PR try to optimize JDKXRLogger and especially the XRSimpleLogFormatter.
On the JDKXRLogger, we keep a Map so we don't need to go through
Logger.getLogger
which is kinda slow.On the XRSimpleLogFormatter side, the biggest win is to avoid calling if necessary:
Both the
record
methods call internallyinferCaller
which it has is own complexity.To identify which of the parameters are effectively used for the format, I went to the "ugly" route as I'm not aware of any API to check if a parameter is present or not.
I've also aligned the default from the configuration file (see Configuration.valueFor( "xr.simple-log-format") at the bottom).
Generally all this work avoid the quite heavy stacktrace walking, which could be quite long in the cases of deeply nested tables.
Additionally, I've optimized also the formatting of the "diagnostic" message. I've removed the use of String.format. See
LogMessageIdFormat
: this will avoid to callString.format(MESSAGE_FORMAT_PLACEHOLDER.matcher(logMessageId.getMessageFormat()).replaceAll("%s"), args);
on each message formatting, which is used quite often if the user use the jdklogger.