System.String and System.Char helpers
CoreLib types served from the framework’s IL: their 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) |
|---|---|---|---|---|---|---|---|
String’s and Char’s library members (src/Csharpc/upstream-types/System.String.txt, CoreLib: the slicer route, string’s instance members hosted as statics; #423) |
110 samples that use strings, chars, culture comparison and casing, regex, JSON writing, paths and URIs byte-identical to real .NET at -O0 and -O2 (220 runs), 8 of them via IL and 4 on wasm32 (gate after merging the integration branch at dc414710); slicer suite 10/10; new 1440, 1441, 1442 and 1445. On main 1440 and 1442 do not compile (string.LastIndexOfAny(char[], int), char.IsAsciiHexDigitLower were missing), 1441 stops on an explicit “not supported” for char.GetNumericValue(string, int) while char.GetNumericValue(char) returned -1 for every non-ASCII numeral (#439) and 1445 treats U+0085, U+1680, U+2028, U+2029, U+202F and U+205F as non-whitespace (#440): two silent differences |
string_throughput 283 352 to 279 696 B (stripped; the shadow measured on the integration head at 53b63ec0) |
6.1 to 5.7 s user | 0.183 to 0.126 s (1.45x faster); 1 472 M to 920 M instructions (callgrind) | 1 653 (corelib/StringOps.cs, most of corelib/StringExtras.cs, culture-string helpers, the C runtime’s whitespace and split helpers in runtime/bclmisc.c, the char.GetNumericValue, IsNullOrWhiteSpace and Split intrinsics); 318 added (corelib/StringRuntime.cs: the helpers codegen calls for concatenation, slicing and comparison; string’s private fields for the IL; slicer support for hosting instance members) |
Flipped (#423). Security: searching, splitting, replacing, padding and casing run CoreLib’s own code with its argument, range and overflow checks and exception texts (ArgumentOutOfRangeException parameter names and messages); the IL reads only _stringLength and ref _firstChar, which the compiler maps onto csharpc’s string layout, and every hosted instance member starts with the callvirt’s null check, so a null receiver throws NullReferenceException as on .NET instead of reading address 0. Whitespace and numeric values come from the framework’s Unicode tables, which fixed two silent differences on main (#439, #440). What csharpc lowers itself keeps priority (length, indexer, equality, concatenation of strings, hashing). |
string_throughput: 279 528 / 1 560 296 B; compile cpu 8.1 / 14.8 s; run 120 / 113 ms (1.06x slower with 21 % fewer instructions; an earlier run 130 / 144 ms, 0.90x: #446); 920 M / 1 171 M instructions |
New samples 1440 (string searching, comparing, casing, trimming, padding, splitting, joining, replacing and copying, with argument checks and
their messages), 1441 (char.GetNumericValue over non-ASCII digits, fractions and numerals: regression for #439), 1442 (char
classification, ASCII helpers, conversion, surrogates and parsing) and 1445 (IsNullOrWhiteSpace and Split() with TrimEntries over every Unicode
whitespace character: regression for #440). 1440 and 1442 case with the tr-TR culture, which .NET on WASI (globalization-invariant)
does not have, so their recordings do not apply there and they are skipped on wasm32 (tests/platform-skips.txt); 1441 and 1445 run there.