-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Suggesting improve initialization performance #753
base: v2.8
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v2.8 #753 +/- ##
============================================
+ Coverage 94.25% 94.31% +0.05%
+ Complexity 2838 2835 -3
============================================
Files 149 149
Lines 5502 5505 +3
Branches 727 723 -4
============================================
+ Hits 5186 5192 +6
+ Misses 176 175 -1
+ Partials 140 138 -2 ☔ View full report in Codecov by Sentry. |
Thanks for the draft! I'm curious to observe your changes. Just let me know when you are done, so I can review the changes. To answer your questions:
Reflections where used for compatibility with Android as Android doesn't provide the class
The JVM start time is nice if tinylog will be initialized much later. However, if you can provide a benchmark that shows significant performance improvements, we can change this. |
(It was tricky to get this project build locally (at least in Intellij), I experienced issues with JDK certificates, probably because of the old jdk version requirement. Don't want to spam more commits to get build in ci working) |
You can fix the build by applying these changes to ModernJavaRuntime.java: @IgnoreJRERequirement
private static final class ClassNameExtractorByDepth implements Function<Stream<StackFrame>, String> {
private final int depth;
private ClassNameExtractorByDepth(final int depth) {
this.depth = depth;
}
@Override
public String apply(final Stream<StackFrame> frames) {
return frames.skip(depth)
.findFirst()
.map(new ClassNameMapper())
.orElse(null);
}
}
@IgnoreJRERequirement
private static final class ClassNameExtractorByLoggerClassName implements Function<Stream<StackFrame>, String> {
private final String loggerClassName;
private ClassNameExtractorByLoggerClassName(final String loggerClassName) {
this.loggerClassName = loggerClassName;
}
@Override
public String apply(final Stream<StackFrame> stream) {
return stream.map(new ClassNameMapper()).dropWhile(new Predicate<String>() {
@Override
public boolean test(final String name) {
return !name.equals(loggerClassName);
}
}).skip(1).findFirst().orElse(null);
}
}
/**
* Mapper for getting the class name from a {@link StackFrame}.
*/
@IgnoreJRERequirement
private static final class ClassNameMapper implements Function<StackFrame, String> {
/** */
private ClassNameMapper() {
}
@Override
public String apply(final StackFrame stackFrame) {
return stackFrame.getClassName();
}
} |
Description
I was happy to see that there are logging libraries in java that don't need multiple 100s of milliseconds just for initialization.
Here I made some suggestions to reduces the tinylogs init performance further by ~10ms
ClassContextSecurityManager()
withStackWalker
getCurrentProcess
(unsure why it uses reflection here)System.currentTimeMillis()
instead of JVM start time. Really unsure if this would be acceptable but this save about 5ms it think.Agreements