Skip to content

HTTP2: Header enumerator allocations #19275

Closed
@JamesNK

Description

@JamesNK

Header enumerator allocations show up:

image

Boxing + allocating a new enumerable:

private static IEnumerable<KeyValuePair<string, string>> EnumerateHeaders(IHeaderDictionary headers)
{
foreach (var header in headers)
{
foreach (var value in header.Value)
{
yield return new KeyValuePair<string, string>(header.Key, value);
}
}
}

IEnumerable is used by QPackEncoder.BeginEncode which is shared code

public bool BeginEncode(IEnumerable<KeyValuePair<string, string>> headers, Span<byte> buffer, out int length)
{
_enumerator = headers.GetEnumerator();
bool hasValue = _enumerator.MoveNext();
Debug.Assert(hasValue == true);
buffer[0] = 0;
buffer[1] = 0;
return Encode(buffer.Slice(2), out length);
}
public bool BeginEncode(int statusCode, IEnumerable<KeyValuePair<string, string>> headers, Span<byte> buffer, out int length)

Metadata

Metadata

Assignees

Labels

HTTP2Perfarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions