Skip to content
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

Avoid allocation of iterator with Tags#empty instance #3313

Merged
merged 2 commits into from
Jul 26, 2022

Conversation

shakuzen
Copy link
Member

Special case calling Tags.and and Tags.of on a Tags.empty() instance to avoid instantiating an iterator for the EMPTY constant static instance.
I've checked this change locally with a JMH test and profiling. This change avoids unnecessary allocation in e.g. the following code:

Tags extraTags = Tags.empty();
Tags anotherTag = Tags.of("a", "b");
Tags combined = anotherTag.and(extraTags);
combined = Tags.concat(extraTags, "a", "b");

This shows up in several places in our instrumentation where we allow passing extraTags to add to meters created by the instrumentation, and the default is no extra tags (Tags.empty()).

@shakuzen shakuzen added enhancement A general enhancement performance Issues related to general performance module: micrometer-core An issue that is related to our core module labels Jul 25, 2022
@shakuzen shakuzen added this to the 1.8.9 milestone Jul 25, 2022
Special case calling Tags.and and Tags.of on a Tags.empty() instance to avoid instantiating an iterator for the EMPTY constant static instance.
@shakuzen
Copy link
Member Author

I've added tests verifying there are now no allocations when using and or of with the empty Tags instance. These tests may be re-worked in the future with #3209.

@shakuzen shakuzen merged commit b93fc3b into micrometer-metrics:1.8.x Jul 26, 2022
@shakuzen shakuzen deleted the tags-and-empty branch July 26, 2022 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-core An issue that is related to our core module performance Issues related to general performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants