Repository: dotnet/aspnetcore
File: src/Http/Http.Extensions/src/HttpRequestJsonExtensions.cs (C#)

Code before:
    {
        ArgumentNullException.ThrowIfNull(request);

        if (!request.HasJsonContentType(out var charset))
        {
            ThrowContentTypeError(request);
        }

        options ??= ResolveSerializerOptions(request.HttpContext);

        var encoding = GetEncodingFromCharset(charset);
        Stream? inputStream = null;

        try
        {
            if (encoding == null || encoding.CodePage == Encoding.UTF8.CodePage)
            {
                if (_useStreamJsonOverload)
                {
                    return await JsonSerializer.DeserializeAsync<TValue>(request.Body, options, cancellationToken);
                }
                return await JsonSerializer.DeserializeAsync<TValue>(request.BodyReader, options, cancellationToken);
            }

            inputStream = Encoding.CreateTranscodingStream(request.Body, encoding, Encoding.UTF8, leaveOpen: true);
            return await JsonSerializer.DeserializeAsync<TValue>(inputStream, options, cancellationToken);
        }
        finally
        {
            if (inputStream is not null)
            {
                await inputStream.DisposeAsync();
            }
        }
    }

    /// <summary>
    /// Read JSON from the request and deserialize to the specified type.
    /// If the request's content-type is not a known JSON type then an error will be thrown.
    /// </summary>
    /// <param name="request">The request to read from.</param>
    /// <param name="jsonTypeInfo">Metadata about the type to convert.</param>
    /// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the operation.</param>
    /// <returns>The deserialized value.</returns>
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
    public static async ValueTask<TValue?> ReadFromJsonAsync<TValue>(
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
        this HttpRequest request,
        JsonTypeInfo<TValue> jsonTypeInfo,
        CancellationToken cancellationToken = default)
    {

Review comment (suggestion):
There are 3 `awaits` in the method body. In order to reduce compiled code size this could be written as
```suggestion
            Task<TResult> task;
            
            if (encoding == null || encoding.CodePage == Encoding.UTF8.CodePage)
            {
                if (_useStreamJsonOverload)
                {
                    task = JsonSerializer.DeserializeAsync<TValue>(request.Body, options, cancellationToken);
                }
                task = JsonSerializer.DeserializeAsync<TValue>(request.BodyReader, options, cancellationToken);
            }
            else
            {
                inputStream = Encoding.CreateTranscodingStream(request.Body, encoding, Encoding.UTF8, leaveOpen: true);
                task = JsonSerializer.DeserializeAsync<TValue>(inputStream, options, cancellationToken);
            }
            
            await task;
```

Does it matter (AOT in mind)?
This [sharplab](https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA+ABATARgLABQGADAAQY4CsA3IRgMzlakDCpA3oad+YxgBzkkpAGIQIACgCWAOwAupBAEpSXHpwI8tpKQDNSEhKQC8x0sSVrtHK9Z4YAnKQCCEpbU12Avra0wANgDOML7qodaOpABCbh52pD6e3IlatgzkghjCUQCGUNLyiiq2GvFZpHI5gQDWcXbhOvqGJmYWDaXxPJU1Ji6xDSl2AcHtDVrd1b0x7gMNDZETdcm2tgAOUFIAbjlyMOQ4wuWuKsYAfEIAdAAiATkAnhI4xBZLpOtbO3sUh9luJudZa63B5PF6ELxAA=) is just a very simple demo, but one can see that the awaiter-setup is reduced by having less `awaits` in the method.

Code after:
    {
        ArgumentNullException.ThrowIfNull(request);

        if (!request.HasJsonContentType(out var charset))
        {
            ThrowContentTypeError(request);
        }

        options ??= ResolveSerializerOptions(request.HttpContext);

        var encoding = GetEncodingFromCharset(charset);
        Stream? inputStream = null;
        ValueTask<TValue?> deserializeTask;

        try
        {
            if (encoding == null || encoding.CodePage == Encoding.UTF8.CodePage)
            {
                if (_useStreamJsonOverload)
                {
                    deserializeTask = JsonSerializer.DeserializeAsync<TValue>(request.Body, options, cancellationToken);
                }
                else
                {
                    deserializeTask = JsonSerializer.DeserializeAsync<TValue>(request.BodyReader, options, cancellationToken);
                }
            }
            else
            {
                inputStream = Encoding.CreateTranscodingStream(request.Body, encoding, Encoding.UTF8, leaveOpen: true);
                deserializeTask = JsonSerializer.DeserializeAsync<TValue>(inputStream, options, cancellationToken);
            }

            return await deserializeTask;
        }
        finally
        {
            if (inputStream is not null)
            {
                await inputStream.DisposeAsync();
            }
        }
    }

    /// <summary>
    /// Read JSON from the request and deserialize to the specified type.
    /// If the request's content-type is not a known JSON type then an error will be thrown.
    /// </summary>
    /// <param name="request">The request to read from.</param>
    /// <param name="jsonTypeInfo">Metadata about the type to convert.</param>
    /// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the operation.</param>