Dit artikel van Stephen Toub beschrijft de technische optimalisaties in .NET 11 ten opzichte van .NET 10. De centrale thema's zijn het verminderen van geheugenallocaties, de inzet van SIMD/vectorisatie via SearchValues en het elimineren van redundante native-naar-managed overgangen.
De belangrijkste verbeteringen zijn onderverdeeld in zes categorieën:
Netwerken & Sockets: Optimalisaties in socket-blocking op Linux en een efficiëntere copy-on-write array voor de Overlapped I/O cache op Windows.
TLS & SslStream: Vermindering van allocaties bij X.500-naamverwerking en certificaatketens, plus een custom BIO-implementatie voor OpenSSL op Linux om staging-kopieën te vermijden.
HttpClient & URI: Gebruik van vectorisatie voor URI-parsing en het precomputeren van headers om collectie-allocaties te voorkomen.
JSON (System.Text.Json): Snellere whitespace-scanning in Utf8JsonReader en geoptimaliseerde bounds checks in Utf8JsonWriter.
Diagnostics & Procesbeheer: Verbeterde proceslancering op macOS via posix_spawn, optimalisaties in W3C Trace IDs en het oplossen van 'false sharing' in de MemoryCache.
Cryptografie: Introductie van ValueAsnReader voor allocatievrije ASN.1-parsing en vectorisatie van tekstvalidatie.
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).
This text is a technical deep-dive by Stephen Toub detailing the performance optimizations introduced in .NET 11 compared to .NET 10. The overarching theme is the reduction of memory allocations, the use of SIMD/vectorization via SearchValues, and the elimination of redundant native-to-managed transitions.
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).
Zichtbare categorieën
Kies welke categorieën je wilt zien.
Over deze site
Waarom Tech-update?
Tech-update is ontstaan omdat ik merkte dat ik dagelijks veel verschillende websites moest bezoeken om interessant technieuws te vinden. Dat kon efficiënter.
Hoe werkt het?
Meerdere keren per etmaal gaat mijn zelfgebouwde AI-agent op zoek naar interessante artikelen op blogs en nieuwssites.
Vindt hij iets relevants, dan wordt het artikel naar het Nederlands vertaald en op Tech-Update geplaatst.
Van ieder artikel maakt de AI ook een korte samenvatting. Zo kun je snel bepalen of het de moeite waard is om het volledige artikel te lezen.
Bij ieder artikel staat altijd een link naar de oorspronkelijke bron (vaak een Engelstalige website).
Artikelen kun je bewaren als favoriet, vastzetten in de zijbalk of terugvinden via de zoekfunctie.
In de instellingen (tandwielikoon rechtsboven) geef je aan in welk soort nieuws je geïnteresseert bent.