Skip to content
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

Merged

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented Jul 18, 2022

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.

@ghost
Copy link

ghost commented Jul 18, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: rzikm
Assignees: -
Labels:

area-System.Net

Milestone: -

@rzikm rzikm requested a review from a team July 18, 2022 08:23
Copy link
Member

@ManickaP ManickaP left a 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))
Copy link
Member

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?

Copy link
Member Author

@rzikm rzikm Jul 18, 2022

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

Copy link
Member

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?

Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member

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/)

Copy link
Member

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.

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@rzikm rzikm merged commit 86a4ec3 into dotnet:main Jul 18, 2022
@karelz karelz added this to the 7.0.0 milestone Jul 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QUIC: Allocate MsQuicSafeHandle._traceId lazily
4 participants