csharpc

System.Number

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.Number’s shortest round-trip digits only: Number.Grisu3.TryRun and Number.Dragon4 (src/Csharpc/upstream-types/System.Number.txt, method roots: the slicer cuts what those methods reach, not the type; #348) a new sample recorded from real .NET (1321: 0.1 + 0.2, subnormals, Epsilon, MaxValue, large exponents, a value Grisu3 gives up on, “R”, “G17”, “G9”, “E”, the parse of each “R” text, and hashes of the text of 100 000 random doubles and floats) and 32 samples that format or parse floating-point numbers, byte-identical at -O0, -O2 and via IL (99 runs); tests/slicer.sh 11 of 11 programs that format a number grow by Dragon4’s big-integer code and power tables: linux-x86_64 numbers 143 688 to 151 880 B (+8 192), net 255 704 to 267 992 (+12 288), json 1 558 752 to 1 571 040, jsonwriter 801 272 to 813 560, regex 818 560 to 834 944, regexoptions 2 046 272 to 2 058 560; hello, exceptions, typeinfo, async, collections, linq unchanged. The StringBuilder throughput program 215 000 to 223 192 B (NativeAOT 1 345 360) StringBuilder throughput program: 6.8 to 7.3 s cpu (NativeAOT publish 15.2 s) StringBuilder throughput program (tools/il-first/bench/stringbuilder_throughput.cs), median of 7: 3 721 to 1 299 ms (NativeAOT 1 761 ms: 2.18x behind to 0.74x); instructions 38.39 G to 10.97 G (NativeAOT 12.36 G). The corelib’s own digit generation (Steele & White on big integers for every value) was 72 % of the instructions 74 deleted and 22 added in corelib/Number.Formatting.cs (the free-format digit generation; BigNum.cs stays, decimal and parsing use it) Digits from IL; the formatter itself stays a shadow until Phase 3 (ADR 0025). wasm32 runs them from the slice cut from the 32-bit CoreLib (#382): the 64-bit CoreLib’s Number.BigInteger has its 64-bit block width and a 59-block nuint buffer baked into the IL, which gave garbage digits on wasm32 in #377’s first CI round (#377 kept the corelib’s own digit generation there until #382). The corelib calls the slice through one contract member, CsharpcCoreLib.Upstream.NumberBridge.ShortestDigits(double|float, Span<byte> digits, out int scale), emitted by the slicer’s csharpc profile and listed in docs/12-corelib.md; the bridge is deleted when number formatting itself flips in Phase 3. Security: the bridge runs upstream’s code on a 769-byte stack buffer of its own (upstream’s DoubleNumberBufferLength) and copies at most the caller’s span length through the span’s checked indexer; no unchecked write leaves the slice. The size cost is a measured speed gain (budgets of numbers and net raised with these numbers). Compiler fixes it needed, all general: method roots in the slicer; [UnsafeAccessor(StaticMethod)] with [UnsafeAccessorType] naming a type of a compiled IL assembly binds at compile time; an IL instance call on a value type’s address that resolves to a [ShadowInstance] static now loads the receiver (it passed the address as the value: UInt128.Lower read from IL was wrong, #359); a built-in type’s static abstract members are found when two slices carry a holder class of the same name (#360, covered by tests/slicer.sh). stringbuilder_throughput (number formatting is most of it): 223 192 / 1 345 360 B; compile cpu 7.3 / 14.8 s; run 1 299 / 1 761 ms (0.74x), was 3 721 / 1 705 ms (2.18x); 10.97 G / 12.38 G instructions, was 38.39 G / 12.36 G

Number formatting and parsing themselves flipped with #426 (the bridge above is deleted): see the number row of System.Globalization.md.