Skip to content

Use Inheritance instead of Composition to Reduce allocation in Request Decompression Middleware #42324

Open
@Kahbazi

Description

@Kahbazi

I've opened this issue to discuss the idea that I've mentioned in here and here now that Request Decompression Middleware is merged.

At the moment IDecompressionProvider is creating a decompression stream and the middleware creates a SizeLimitedStream which wraps the other one. We could reduce this two streams into one if the IDecompressionProvider returns a stream that also handle size limit check, and the middleware only create SizeLimitedStream if the returned stream from the IDecompressionProvider is not marked with IDontNeedWrapper interface.

+internal interface IDontNeedWrapper {}
+internal sealed class GZipRequestDecompressionBody : GZipStream, IDontNeedWrapper {}
+internal sealed class DeflateRequestDecompressionBody : DeflateStream , IDontNeedWrapper {}
+internal sealed class BrotliRequestDecompressionBody : BrotliStream, IDontNeedWrapper {}

The new types for this change are all private, so there's no new public types. By doing this we would reduce one allocation per requests when request body is compressed by GZip, Deflate or Brotli.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Perfarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsinvestigate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions