csharpc

System.Net.Primitives

A library or CoreLib type served from the framework’s IL: its row of the per-library table of ADR 0023 (columns explained there, under “Measurements”).

Library (switch) Correctness (samples from IL) Binary size, IL / shadow Compile cpu, IL / shadow Speed, IL / shadow (time) Lines removed on a flip Decision NativeAOT on the same host, csharpc / NativeAOT (tools/il-first/measure-aot.sh: stripped size; compile cpu; run, median of 7; instructions)
System.Net.Primitives (IPAddress, IPEndPoint, EndPoint, IPNetwork; the rest of the assembly was IL already, ADR 0013) the 46 networking samples (IPAddress/IPEndPoint/IPNetwork, Dns, Socket, HttpClient, SslStream, cookies, credentials) pass at -O0 and -O2 (92 runs), nine of them also with --via-il; two new samples recorded from real .NET: 1316 (parsing of untrusted text: inet_aton limits, IPv6 compression and embedded IPv4, scope ids, brackets and ports, the span and UTF-8 overloads, TryFormat) and 1317 (IPEndPoint.Serialize/Create, SocketAddress). The shadow was silently wrong on scope ids: fe80::1%, fe80::1%nosuchif0, fe80::1%2%3, fe80::1%4294967296 and fe80::1%-1 are valid addresses with scope 0 in .NET and were rejected; it also lacked the span/UTF-8 Parse/TryParse, TryFormat and Serialize/Create (compile errors). SocketException stays a shadow (the socket engine’s native error and text), and the two internal classes that P/Invoke libSystem.Native, SocketAddressPal and InterfaceInfoPal, are a 196-line contract over the socket engine’s sockaddr layout and if_nametoindex (corelib/Net/SocketAddressPal.cs) tests/size/net.cs 171 480 to 255 976 B (1.49x; NativeAOT 1 365 832), the speed program 148 872 to 246 104 (NativeAOT 1 357 608), sample 195 182 440 to 267 208, 615 175 608 to 259 640: the IL’s generic parser and formatter over char and byte, UInt128 in IPNetwork and the number formatting they reach. Before a general fix in this PR it was 393 536: a boxed UInt128’s ISpanFormattable slot went through the formatter switch of every primitive (decimal, DateTime with the calendars); now it formats only UInt128 (tests/size/json.cs 1 572 320 to 1 559 040 from the same fix). The other tests/size programs are unchanged net.cs 4.8 to 6.3 s user (wall 4.6 to 5.4; NativeAOT publish 9.9 s user, 13.4 wall) IPAddress.Parse + ToString + GetAddressBytes, 2 M iterations over 8 addresses, median of 7: shadow 336 ms, IL 237 ms (0.71x), NativeAOT 295 ms; the checksum equals real .NET 633 (Net/IPAddress.cs 509, Net/IPNetwork.cs 124; SslClientHelloInfo, a System.Net.Security type, moved to Net/SslStream.cs); 196 added for the sockaddr contract Flipped (#326). Security: the hand-written parsers of untrusted text (IPAddress, IPEndPoint, IPNetwork) are replaced by the framework’s own IPAddressParser/IPv4AddressHelper/IPv6AddressHelper, which are fuzzed upstream and bound every component (sample 1316 pins the limits); cookie parsing was already the framework’s IL. The new contract code bounds every sockaddr access by the buffer length (ArgumentOutOfRangeException("socketAddressSize"), libSystem.Native’s EFAULT) and passes if_nametoindex a NUL-terminated copy. General pieces added on the way: MemoryExtensions.TryWriteInterpolatedStringHandler from the CoreLib slice (nested types of a type outside the slice are hoisted), UTF-8 Parse/TryParse for the remaining integer types, Vector128 array and span Create/CopyTo, a program that names any System.Net namespace takes System.Net.Primitives (the corelib’s Socket and Dns shadows return its types). net_throughput: 255 272 / 1 361 728 B; compile cpu 7.9 / 13.1 s; run 1 279 / 1 110 ms (1.15x); 10.98 G / 10.63 G instructions; net: 255 720 / 1 365 832 B; compile cpu 9.8 / 14.4 s; run 2 / 9 ms (0.27x); 0.3 M / 5.2 M instructions