Skip to content

Conversation

@akiselev98
Copy link
Contributor

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.

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.
karianna
karianna previously approved these changes Oct 19, 2025
@obourgain
Copy link

this is indeed faster, about twice faster for my use case too.

@karianna
Copy link
Member

@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];
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants