-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Implement new TagsList
constructor on Measurement
#105011
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
Conversation
Note regarding the
|
Note regarding the
|
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti |
6f71707
to
d137fd0
Compare
...aries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Huo Yaoyuan <[email protected]>
With the params span ctor, why were there boxing allocations? |
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Measurement.cs
Show resolved
Hide resolved
This is because the constructor accepting the TagList list = new TagList { { "Key", "Value" } };
Measurement<int> measurement = new Measurement<int>(10, list);
|
Ok, I thought Steve was talking about doing e.g. Measurement<int> measurement = new Measurement<int>(
10,
new KeyValuePair<string, object?>("a", "b"),
new KeyValuePair<string, object?>("c", "d"),
new KeyValuePair<string, object?>("e", "f"),
new KeyValuePair<string, object?>("g", "h")); which should no longer allocate or box at the call site. That should now bind to the |
/// </summary> | ||
/// <param name="value">The value of the measurement.</param> | ||
/// <param name="tags">A <see cref="TagList"/> containing the <see cref="KeyValuePair{TKey, TValue}"/> tags associated with the measurement.</param> | ||
public Measurement(T value, in TagList tags) |
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.
Do we have tests for this? I don't see any in this PR.
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.
var measurement = new Measurement<int>(i, tags); |
Closes #104015
Adds a new constructor, as proposed, to optimize the scenario where a
TagsList
is provided to construct a newMeasurement
. This avoids boxing allocations and reduces execution time.I also took the chance to fix and clarify the XML doc comments.
cc @tarekgh