-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
area-System.Net.HttpenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionstenet-performancePerformance related issuePerformance related issue
Milestone
Description
ByteArrayContent's ctor calls HttpContent.SetBuffer:
| SetBuffer(_content, _offset, _count); |
Which then allocates a MemoryStream:
runtime/src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs
Lines 134 to 137 in 39cde70
| internal void SetBuffer(byte[] buffer, int offset, int count) | |
| { | |
| _bufferedContent = new MemoryStream(buffer, offset, count, writable: false, publiclyVisible: true); | |
| } |
This stream is not needed in the common case: if passing as a request content, it goes unused (or could be elided in other ways). It is only ever needed if the user calls GetStreamAsync() (or a few related ones) on their own content.
We should try to make this allocation only as needed, not every time. This also affects StringContent, which inherits from ByteArrayContent.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.Net.HttpenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionstenet-performancePerformance related issuePerformance related issue