Range Indexer

With C# 12's collection expression feature, the range indexers has become also more powerful.

These two constructs along with the C#'s spreads feature allow to easily create new collections by slicing and concatenating existing ones. For example, given the following snippet:

int[] a = [1, 2];
int[] b = [3, 4, 5];
int[] c = [..a, ..b[..1]];

When executing the snippet, variable c will reference an integer array containing 1 2 and 3 values. While these operations are universal in many languages for a longer time, they are only introduced as new in C# 12.

Find out more


Large HTTP/2 Header Frames

In a previous post I explored how HTTP2 handles header frames in .NET 8. In this post I explore how it is planned to handle larger HTTP2 response header values.

Recap

  • RFC7540 describes the HTTP/2 protocol's related details.

  • In HTTP/2 a request-response pair is serialized in a stream.

  • A stream consists of message frames.

  • Frames have a type, frame header, a given size and corresponding data. Frames are associated with a given stream with the stream ID.

  • HTTP/2 requests start with HEADER frame. A header frame may be followed by CONTINUATION frames containing further headers.

  • The HTTP/2 request headers HPack encoded and split into HEADER and CONTINUATION frames.

  • In ASP.NET Core's Kestrel HPackHeaderWriter static class writes the headers.

    • HPackHeaderWriter iterates over the headers/trailers (except for the response status header which is written separately) using the Http2FrameWriter types.

  • Http2FrameWriter creates the buffer which it passes as a Span<byte> to the header writer. The default size of the buffer is 16K, but it can be updated via Kestrel's option by setting the Http2Limits's MaxFrameSize property. Clients can also influence the frame size by sending a value in the SETTING frame.

Planned changes

Find out more


HTTP/2 Header Frames

I have recently come across a GitHub issue 'Allow the encoder to split headers across frames' in the dotnet/aspnetcore repository, that made me look into and understand some of the details how HTTP/2 encodes headers.

In this post I will summarize my key findings on how ASP.NET Core writes these headers today. In this post I use version ASP.NET Core 8 with .NET 8. My findings are based on the current state of the source code and the corresponding RFC7540.

HTTP/2

Here are my key learnings:

Find out more


Collection Expressions

C# 12 introduced a new language feature: collection expressions or collection literal. It provides a neat way to initialize collections: enumerables, lists, spans, etc.

An example of using the collection expressions:

int[] a = [6, 7];

In this case the compiler generates code for variable a referencing an array with two elements: 6 and 7.

Find out more


Preview .NET with BenchmarkDotnet

In a previous post I explored how someone can setup a custom .NET SDK and Runtime for development. It consists of a script downloads the .NET runtime to a custom folder, another script that sets up environment variables to use the given .NET version with Visual Studio and a global.json / nuget.config for build time dependencies with Visual Studio and the .NET CLI.

In this post I evolve the previous setup:

  • Install and use an alpha release of .NET 10 Runtime with .NET 9 SDK.

  • Setup BenchmarkDotNet performance measurements to use .NET 10

Update the runtime to .NET 10

Find out more