Replace usages of io.micrometer.core.instrument.Tags with Iterable<Tag> #1612
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
io.micrometer.core.instrument.Tags
turns out to be a poor intermediate representation ofIterable<Tag>
. In addition to being immutable and requiring a new instance for every call, it sorts and deduplicates elements on every operation which can lead to some significant CPU overhead on hot paths and/or with large numbers of tags:https://github.com/micrometer-metrics/micrometer/blob/a56b968ba5b3db9b5e4a4feac813080783a16f5f/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java#L43-L47
All of the
tags
builder methods callTags::and
and there's no optimization for an initially empty state or the passedIterable<? extends Tag>
being aTags
instance, so you pay that overhead when finally adding the tags, no matter how the tags are constructed:This replaces all direct usages of
Tags
withIterable<Tag>
and avoids calling thetag
builder methods more than once.