Skip to content

Reduce allocations in Quic/HTTP3 - #104394

Merged
MihaZupan merged 2 commits into
dotnet:mainfrom
MihaZupan:quic-allocs
Jul 8, 2024
Merged

Reduce allocations in Quic/HTTP3#104394
MihaZupan merged 2 commits into
dotnet:mainfrom
MihaZupan:quic-allocs

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

As of #104035 we're now waiting for WritesClosed on every request, and paying for the allocations backing that Task. This PR attempts to claw that perf back.

This does a couple of things:

  • if the ResettableValueTaskSource's final task was already signaled by the time someone first asked for the Task, avoid allocating the intermediate TaskCompletionSource and its Task.
  • Move the waiting on WritesClosed later on in Http3's SendAsync (after receiving the response) to make it more likely that WritesClosed will have been completed by the time we check, thus avoiding the allocations.
  • Honors the cancellationToken while waiting for WritesClosed -- @ManickaP I'm guessing that's desirable here?
  • Avoids the state machine allocation in FlushSendBufferAsync

@MihaZupan MihaZupan added this to the 9.0.0 milestone Jul 3, 2024
@MihaZupan
MihaZupan requested review from a team and ManickaP July 3, 2024 18:23
@MihaZupan MihaZupan self-assigned this Jul 3, 2024
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@MihaZupan

Copy link
Copy Markdown
Member Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@rzikm rzikm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Before this PR, WritesClosed was handled right after completing writes, logically next to each other. Now, the logic is split in different places. I know it's more efficient, but IMHO it's much harder to follow now and not mess up in the future.

I'll not block this PR on this, I'm just sharing my perspective.

@MihaZupan

Copy link
Copy Markdown
Member Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@MihaZupan
MihaZupan merged commit 2d92034 into dotnet:main Jul 8, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 9, 2024
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.

3 participants