-
Notifications
You must be signed in to change notification settings - Fork 36
LoggentriesAppender: memory efficient concatenation for layout.ignoresThrowable() #53
base: master
Are you sure you want to change the base?
Conversation
buffSize += 1; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some things that might saved more cpu cycles here.
Replacing:
int buffSize = formattedEvent.length();
buffSize += EXCEPTION_SEPARATOR.length();
By:
int buffSize = formattedEvent.length() + EXCEPTION_SEPARATOR.length();
And removing from the loop:
if (i < len - 1) {
buffSize += 1;
}
And adding after for loop:
buffSize += len - 1;
It would save... ;)
…sThrowable() Allocate just the right amount of characters once. Before this change the stack gets concatenated with string concatenation operator. In such scenary, the optimization proposed on JLS-15.18.1 may not apply to the code valid (it is not a one liner). Oracle 1.8.0_77i7-4510U CPU @ 2.00GHz, for 60 deep stacktrace exception ("a tipical exception") Legacy code (extracted as an static method): n: 98,999 min: 210,397 nanoseconds max: 5,640,727 nanoseconds mean: 256,441 nanoseconds std dev: 68,782 nanoseconds median: 242,984 nanoseconds After: n: 98,999 min: 2,555 nanoseconds max: 2,930,444 nanoseconds mean: 5,038 nanoseconds std dev: 2,2034 nanoseconds median: 3,803 nanoseconds Methodology: final int n = 100000; final DescriptiveStatistics statistics = new DescriptiveStatistics(n); final String []stack = { // .... }; for (int i = 0 ; i < n ; i++) { final long t0 = System.nanoTime(); LogentriesAppender.appendFormatedEvent("fooo", stack); final long t1 = System.nanoTime(); if(i > 1000) { statistics.addValue(t1-t0); } } System.out.println(statistics); DescriptiveStatistics is provided by org.apache.commons:commons-math:2.2
@danilosterrapid7 you are right! commit updated! |
@jcodagnone before doing any more hating, are you running this on Android? |
@m0wfo no, I'm not running it on Android (but I know that StringBuilder is available there), why you ask? I was reviewing the library before adding it to a project because I wanted to understand if it may block program if the network was slow; and I saw these possibles enhances. |
@scawley-r7 a bit ashamed, I really have forgot it. Besides, no one checked it out either. Is it ok to get it merged if you do not have any comment on that? |
@stopal-r7 ^^^ |
Allocate just the right amount of characters once.
Before this change the stack gets concatenated using the string concatenation operator.
In such scenery, the optimization proposed on JLS-15.18.1 may not apply to the code valid
(it is not a one liner).
Oracle 1.8.0_77 i7-4510U CPU @ 2.00GHz, for 60 deep stacktrace exception ("a typical exception")
Legacy code (extracted as an static method):
After:
Methodology:
DescriptiveStatistics is provided by org.apache.commons:commons-math:2.2