-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Allocate MsQuicSafeHandle._traceId lazily #72360
Allocate MsQuicSafeHandle._traceId lazily #72360
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsCloses #71935. I tried running it in our benchmarks via Crank but I have not observed any significant perf difference. I also put a breakpoint in the ToString() of the
|
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.
One question, otherwise looks good.
$"GetParam({handle}, {parameter}) failed"); | ||
(byte*)&value); | ||
|
||
if (StatusFailed(status)) |
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.
What's the difference between this and what ThrowHelper.ThrowIfMsQuicError
does?
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.
It does not force creating the interpolated string (and avoids call to SafeMsQuicHandle.ToString()
) on success path
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.
If we feel strongly about not creating _traceId
we might add condition in SafeMsQuicHandle.ToString
. If we don't, and we're ok allocating it in case of an error, we could add overload for ThrowIfMsQuicError
that takes FormattableString
.
I got the feeling that this will creep back in if we don't take precautions. What do you think?
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.
Can we use FormattableString in a way that does not cause excess allocations? I have never used it and the few tutorials I found look like the args are embedded in the instance (which would imply allocating one instance per call)
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.
FormattableString will incur its own costs: you won't get a string formatted, but you will get two allocations, for the FormattableString itself and for the object[] args array.
I think what you have here is fine.
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.
(If you really wanted to, you could implement a custom interpolated string handler, but I don't think it's worth it in this case: https://devblogs.microsoft.com/dotnet/string-interpolation-in-c-10-and-net-6/)
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, I should have realize that it incurs its own allocations. Custom implementation is certainly not worth it.
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.
Closes #71935.
I tried running it in our benchmarks via Crank but I have not observed any significant perf difference.
I also put a breakpoint in the ToString() of the
MsQuicSafeHandle
to really check that we don't force the allocation anywhere.