-
Couldn't load subscription status.
- Fork 163
Optimize decorator parsing #458
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
base: main
Are you sure you want to change the base?
Conversation
Profiling showed that a relatively high percentage of CPU time and memory allocations are coming from decorator parsing. This makes sense, since this parsing is applied to every unified log line which goes through gctoolkit. To speed things up, we: - Fold the tags regex into the broader decorator regex, avoiding the need for a second matcher, and removing the need for an expensive negative lookbehind in the tag pattern - Add a start of line anchor to the decorator regex - Defer sanitization of tags until getTags() is called for the first time To reduce unnecessary memory allocations, match groups are retrieved once and stored in an array. In testing, these optimizations cut the running time of gctoolkit roughly in half.
parser/src/main/java/com/microsoft/gctoolkit/parser/unified/UnifiedLoggingTokens.java
Show resolved
Hide resolved
parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/Decorators.java
Outdated
Show resolved
Hide resolved
…ifiedLoggingTokens.java
|
this is indeed faster, about twice faster for my use case too. |
|
@johnoliver can you review as well |
| if ( decoratorMatcher.group(i) != null) | ||
| // Retrieving a group from a matcher calls substring each time | ||
| // Store all the groups in an array ahead of time to avoid paying this cost unnecessarily | ||
| decoratorGroups = new String[11]; |
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.
new String[decoratorMatcher.groupCount()] might be a bit more robust here
Profiling showed that a relatively high percentage of CPU time and memory allocations are coming from decorator parsing. This makes sense, since this parsing is applied to every unified log line which goes through gctoolkit.
To speed things up, we:
To reduce unnecessary memory allocations, match groups are retrieved once and stored in an array.
In testing, these optimizations cut the running time of gctoolkit roughly in half.