Here is a summarized breakdown of the improvements by category:

1. Networking & Sockets

  • Socket Blocking (Linux): ConnectAsync now flips the socket back to blocking mode before returning. This prevents subsequent synchronous Send/Receive calls from paying the overhead of "emulated" non-blocking operations.
  • Overlapped I/O Cache (Windows): Changed the global cache for Winsock function pointers from a locked List<T> to a copy-on-write array. This removes lock contention when many sockets perform their first async operation concurrently.

2. TLS & SslStream

  • Allocation Reductions:
  • Removed intermediate byte[] allocations during X.500 name processing on Windows and macOS by using ReadOnlySpan<byte>.
  • Used stackalloc for small certificate chains on macOS to avoid IntPtr[] allocations.
  • OpenSSL Optimization (Linux): Implemented a custom BIO (Basic I/O) that allows OpenSSL to read and write directly to managed buffers, eliminating expensive "staging" copies of encrypted data.

3. HttpClient & URI

  • SocketsHttpHandler:
  • Precomputes Accept-Encoding headers to avoid collection allocations.
  • Optimized MultipartContent by caching encoded delimiter bytes instead of regenerating them during every serialization.
  • Uri Parsing:
  • Used SearchValues and IndexOfAny to find delimiters using vectorization (scanning multiple characters at once).
  • Introduced a fast path for ASCII letters/digits during canonicalization.
  • Changed normalization to rebuild the final string in one pass rather than creating multiple temporary strings.

4. JSON (System.Text.Json)

  • Utf8JsonWriter: Uses SearchValues to find characters that need escaping and optimizes bounds checks to allow the JIT to remove redundant checks during writes.
  • Utf8JsonReader: Uses IndexOfAnyExcept to skip whitespace in indented JSON documents much faster.

5. Diagnostics & Process Management

  • Distributed Tracing: Replaced manual loops with SearchValues for validating W3C Trace IDs and encoding baggage.
  • Process APIs:
  • Unix: Optimized environment variable marshalling into a single native block to avoid multiple small allocations.
  • macOS: Switched from fork/exec to posix_spawn for faster process launching.
  • Linux/macOS: Optimized ProcessName to perform a narrow OS query instead of fetching all process metadata.
  • Windows: Decoupled local and remote process paths, allowing the Native AOT trimmer to remove unused remote-process code, reducing binary size.
  • Metrics & Logging:
  • Removed array allocations for single-value ObservableInstrument measurements.
  • Fixed "False Sharing" in MemoryCache by padding counters across separate cache lines to prevent CPU core contention.
  • Reuses ThreadStatic buffers for EventSource JSON logging.

6. Cryptography

  • ASN.1 Parsing: Introduced ValueAsnReader (a ref struct), allowing the parser to use spans and avoid allocating objects for nested sequences.
  • Text Validation: Vectorized the validation and transcoding of ASN.1 strings (like IA5String and VisibleString).
  • Hashing & Encryption:
  • SHA-1: Added a "one-shot" path for non-security uses (like public-key tokens) that keeps the state on the stack.
  • AES Key Wrap: Windows and Apple implementations now reuse a single native cipher for the entire wrap/unwrap operation instead of recreating it for every block.
  • Certificate Validation (Linux): Added an in-memory cache for parsed CRLs (Certificate Revocation Lists) and shared asynchronous downloads for missing issuer certificates (AIA).