Skip to content

perf: HttpConnection write bytes directly into the buffer#100

Merged
HofmeisterAn merged 6 commits intotestcontainers:mainfrom
campersau:httpconnectionbuffer
Apr 23, 2026
Merged

perf: HttpConnection write bytes directly into the buffer#100
HofmeisterAn merged 6 commits intotestcontainers:mainfrom
campersau:httpconnectionbuffer

Conversation

@campersau
Copy link
Copy Markdown

Benchmark on net10.0

Method Mean Error StdDev Gen0 Allocated
PR 710.7 ns 14.01 ns 20.53 ns 0.0467 616 B
main 786.3 ns 15.67 ns 23.45 ns 0.1125 1480 B

Copy link
Copy Markdown
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the many preprocessor directives make the code hard to read. I propose using proper abstraction (a base class) and separate implementations for the underlying buffer (ArrayBufferWriter and MemoryStream) that handle writing to the buffer. Then we can use a single preprocessor directive to include the class entirely, like we're doing here. Then we don't need if-else in HttpConnection.

@campersau
Copy link
Copy Markdown
Author

Do you mean something like this dd4d234?

@HofmeisterAn
Copy link
Copy Markdown
Collaborator

Do you mean something like this dd4d234?

See my recent changes, I was thinking of something like this. WDYT? I'll take another look tomorrow, but I think it's easier to read now.

@campersau
Copy link
Copy Markdown
Author

Ah ok. Yes, looks good to me!

Comment thread src/Microsoft.Net.Http.Client/HttpConnection.cs
Comment thread src/Microsoft.Net.Http.Client/HttpConnection.cs
@HofmeisterAn HofmeisterAn changed the title Perf: HttpConnection write bytes directly into a buffer perf: HttpConnection write bytes directly into the buffer Apr 23, 2026
@HofmeisterAn HofmeisterAn merged commit b72f286 into testcontainers:main Apr 23, 2026
15 checks passed
@HofmeisterAn HofmeisterAn added the enhancement New feature or request label Apr 23, 2026
@campersau campersau deleted the httpconnectionbuffer branch April 23, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants