Minor perf improvement for metric (#3862)
This commit is contained in:
parent
6c3beef649
commit
91a9b7c549
|
|
@ -201,22 +201,25 @@ namespace OpenTelemetry.Metrics
|
|||
return -1;
|
||||
}
|
||||
|
||||
// Note: We are using storage from ThreadStatic for both the input order of tags and the sorted order of tags,
|
||||
// Note: We are using storage from ThreadStatic (for upto MaxTagCacheSize tags) for both the input order of tags and the sorted order of tags,
|
||||
// so we need to make a deep copy for Dictionary storage.
|
||||
var givenKeys = new string[length];
|
||||
tagKeys.CopyTo(givenKeys, 0);
|
||||
if (length <= ThreadStaticStorage.MaxTagCacheSize)
|
||||
{
|
||||
var givenKeys = new string[length];
|
||||
tagKeys.CopyTo(givenKeys, 0);
|
||||
|
||||
var givenValues = new object[length];
|
||||
tagValues.CopyTo(givenValues, 0);
|
||||
var givenValues = new object[length];
|
||||
tagValues.CopyTo(givenValues, 0);
|
||||
|
||||
var sortedTagKeys = new string[length];
|
||||
tempSortedTagKeys.CopyTo(sortedTagKeys, 0);
|
||||
var sortedTagKeys = new string[length];
|
||||
tempSortedTagKeys.CopyTo(sortedTagKeys, 0);
|
||||
|
||||
var sortedTagValues = new object[length];
|
||||
tempSortedTagValues.CopyTo(sortedTagValues, 0);
|
||||
var sortedTagValues = new object[length];
|
||||
tempSortedTagValues.CopyTo(sortedTagValues, 0);
|
||||
|
||||
givenTags = new Tags(givenKeys, givenValues);
|
||||
sortedTags = new Tags(sortedTagKeys, sortedTagValues);
|
||||
givenTags = new Tags(givenKeys, givenValues);
|
||||
sortedTags = new Tags(sortedTagKeys, sortedTagValues);
|
||||
}
|
||||
|
||||
lock (this.tagsToMetricPointIndexDictionary)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace OpenTelemetry.Metrics
|
|||
{
|
||||
internal sealed class ThreadStaticStorage
|
||||
{
|
||||
private const int MaxTagCacheSize = 8;
|
||||
internal const int MaxTagCacheSize = 8;
|
||||
|
||||
[ThreadStatic]
|
||||
private static ThreadStaticStorage storage;
|
||||
|
|
|
|||
Loading…
Reference in New Issue