Improve Http.sys allocation profile and performance
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
AB#1240693
This isn't urgent in anyway but I wanted to keep track of the low hanging performance fruit in HttpSys server:
## Http.sys optimizations
### General
- Feature collection generation similar/uses kestrels (https://github.com/dotnet/aspnetcore/issues/31323)
- Headers generation shares with Kestrel (https://github.com/dotnet/aspnetcore/issues/31323)
### Accept loop
- Use a single preallocated native overlapped per server (dispose after the accept loop is over)
- This means getting rid of SafeNativeOverlapped (or making it a struct)
- Make the NativeRequestContext a struct, it's basically a wrapper around a byte with helpers to extra data from a blob of memory.
- Another option would be to merge it into the feature collection implementation (similar to IIS)
- Allocate a single feature collection object that implements the request and response contract. Today we have 2 objects maybe out of legacy?
### Bodies
- Synchronous read can be implemented by pinning the user buffer (or we can throw like we do in Kestrel)
- Implement span overloads (these are missing)
- Remove Begin/End implementations, and use Task.ToApm helpers to implement Begin/End over
- The Task/ValueTask based overloads (the Memory and Span overloads should be the only implementation)
- Remove IAsyncResult implementations
- Implement pattern from IIS implementation IValueTaskSource based implementations of IO
- Single object re-used for IO (each request body), no overlapping operations allowed.
- Reuse pre-allocated overlapped during reads and writes
- Potentially use memory pool for output
- This removes the need to pin user buffers and avoid fragmentation
- May result in more copies (user buffer-> pinned buffer)
## Client cert loader
- TBD
Contributor guide
Assessment
This issue has not been assessed yet.