Skip to content

HttpClient: Header allocations #31235

@JamesNK

Description

@JamesNK

I have a micro-benchmark that simulates a gRPC call. Instead of calling the underlying SocketsHttpHandler, a mock handler returns a manually created HttpResponseMessage.

A lot of the allocations in this scenario are related to HTTP headers (obviously they would be less significant in a real world HTTP call).

image

A request/response has many header collections, and most of the time these header collections are going to be small.

  • HttpRequestMessage.Headers
  • HttpRequestMessage.Content.Headers
  • HttpResponseMessage.Headers
  • HttpResponseMessage.Trailers
  • HttpResponseMessage.Content.Headers

At the moment an internal dictionary is used in each. This seems unnecessary given their typically small size. Can the internal storage of headers be optimized?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.HttpenhancementProduct code improvement that does NOT require public API changes/additionstenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions