Conversation
syphe
left a comment
There was a problem hiding this comment.
Another reason this is a good idea, is that const is determined at compile time when being referenced elsewhere, where as 'static readonly' will cause the value to be referenced at runtime instead.
|
Let's look closer at those extra allocations, I don't see where they would be coming from. |
| { | ||
| private const string ActivitySourceName = "OmexActivitySource"; | ||
| private const string ActivitySourceVersion = "1.0.0.0"; | ||
| private static readonly string s_activitySourceName = "OmexActivitySource"; |
There was a problem hiding this comment.
This class is already static so I expect these shouldn't be changed.
| internal static class ReplayebleActivityExtensions | ||
| { | ||
| private const string ReplayableLogKey = "ReplayableLogKey"; | ||
| private static readonly string s_replayableLogKey = "ReplayableLogKey"; |
| /// Changing this name will mean that consumers might miss telemetry events | ||
| /// </remarks> | ||
| internal const string DiagnosticListenerName = "Microsoft.Omex.Extensions.Services.Remoting"; | ||
| internal static readonly string DiagnosticListenerName = "Microsoft.Omex.Extensions.Services.Remoting"; |
| /// link: https://www.w3.org/TR/trace-context/ | ||
| /// </remarks> | ||
| private const string TraceParentHeaderName = "omex-traceparent"; | ||
| private static readonly string s_traceParentHeaderName = "omex-traceparent"; |
I take it that the issue is that as transient instances get created and destroyed as part of their DI lifecycle, the const values are being repeatedly allocated. |
They shouldn't be, CLI ensures that each string constant exists as a singular object (though you can trick it if you try hard). I was talking to Andrey separately, profiler detects multiple allocations of some strings but I'm sure this PR won't fix it. |
artempushkin
left a comment
There was a problem hiding this comment.
I'll block this to prevent accidental merging.
Using
constresults in a new allocation each time it's used. The most common exception would be health check markers we have that used each time we mark activity as healthcheck or check it.This PR replaces
constwithstatic readonlyto avoid additional allocations.