-
Notifications
You must be signed in to change notification settings - Fork 11
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
Compact MetricName tag map implementation #1368
Conversation
Generate changelog in
|
static final TagMap EMPTY = new TagMap(new String[0]); | ||
|
||
private final String[] values; | ||
private final int hash; |
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.
I went back and forth on pre-computing the hash since the MetricName implementation already caches the hashCode.
It would be helpful for map wrappers with additional entries, however that case may perform better if we flatten it an create a new TagMap instance with an array two entries larger (assuming relatively few entries, which is generally true). Note that I have not verified this, so take it with a grain of salt.
In the common TaggedMetricSet case which applies additional entries, we never hash the name. It is passed to the metric log subscriber, and only hashed for gauges to ensure we're not blocked recording the same gauge twice.
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.
yeah, we could drop the hash field as all the current usages of TagMap
will now compute the hashCode after creating a TagMap
, and we now do create a new TagMap when adding an entry in https://github.com/palantir/tritium/pull/1368/files#diff-07d251c64776a9fd9112f154669063beff3ea2c65f4bece8c4bf9c24acce747aR87
Dropped the hash
field from #1367
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.
Dropped hash
field here as well
I'm preparing a change to remove the ExtraEntryMap wrapper in favor of using TagMap directly |
tritium-registry/src/main/java/com/palantir/tritium/metrics/registry/TagMap.java
Outdated
Show resolved
Hide resolved
NestedMetricsBenchmark resultsBenchmarks after:
Benchmarks before:
AnalysisThese don't seem to tell the whole story, they measure object creation, but we never consume the metricname components, there's no iteration over keys. More representative benchmarksWith the benchmark changes introduced in 173efe9 we have larger tag maps, and the consumer blackholes the safeName and all tag key/value pairs. After:tags forEach(biconsumer)
tags entrySet + enhanced for-loop
Before:tags forEach(biconsumer)
tags entrySet + enhanced for-loop
|
I was curious if the Adding this to the consumer: blackhole.consume(name.hashCode()); Resulted in:
The optimization gives us a 10% uplift, which is a very small faction of the improvement from this PR |
👍 |
Released 0.41.0 |
Before this PR
Excessive cost to create and store MetricName due to tags.
After this PR
==COMMIT_MSG==
Compact MetricName tag map implementation
==COMMIT_MSG==
Possible downsides?
Custom code