csharpc

System.Text.RegularExpressions

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.Text.RegularExpressions 20 of 22 before the flip (the 2 failures were [GeneratedRegex]: csharpc’s own generator called into the shadow Regex); after linking the SDK’s generator every regex sample passes, [GeneratedRegex] ones included, plus a new NonBacktracking sample (1290) 3.35x over 8 samples in the A/B (13.9 against 4.1 MB). Final, stripped -O2 x86-64: 1.43x (744 912 against 520 248 B) for new Regex(pattern) programs, 3.6x to 3.8x (1.90 to 2.01 MB against 0.53 MB) once a constructor or static method takes RegexOptions, which reaches the NonBacktracking engine (SymbolicRegexRunnerFactory, found with CSHARPC_WHY_LOWERED); a program using [GeneratedRegex] shrinks (415 504 against 548 792 B: the generated matcher replaces the interpreter) 2.24x in the A/B; final: 0.85x to 2.1x per sample (153 against 75 CPU s for 290, 79 against 73 for 291, 68 against 80 for 305) 0.71x on the throughput program (992 to 700 ms: 1.4x faster); start-up dominated samples tie 17 174 (corelib/Regex 16 830, Frontend/GeneratedRegex*.cs 344); the flip PR’s total against main is 17 406 deletions (135 insertions) with the ownership-map rows, the fuzzer’s regex cases and docs Flipped (#206): correct and faster; the size cost is the NonBacktracking engine every options-taking Regex construction reaches (follow-up: a tighter closed world or constant propagation of RegexOptions). Budgets: tests/size/regex.cs 815 104 B and regexoptions.cs 1 929 216 B on linux-x86_64; programs that do not use Regex are byte-identical (hello 28 536, linq 164 552, collections 140 856, numbers 129 048, exceptions 36 920, typeinfo 43 792, async 156 096). regex_throughput: 2 060 168 / 2 519 208 B; compile cpu 47.7 / 16.1 s; run 103 / 106 ms (0.98x); 0.59 G / 0.69 G instructions; regex: 818 592 / 2 301 032 B; compile cpu 18.8 / 28.6 s; run 3 / 10 ms (0.25x); 0.7 M / 5.9 M instructions