System.Memory
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.Memory (System.Memory: ArrayBufferWriter<T>, ReadOnlySequence<T>, SequenceReader<T>, SequencePosition, MemoryPool<T>, EncodingExtensions) |
14 of 14 samples that use these types byte-identical to real .NET at -O0, -O2 and --via-il (1051, 1250 both, 1251, 1266, 1281, 310, 483, 505, 506, 834, 835, 846, 849); the ownership map’s Memory<T> blocker (csharpc’s Memory<T> does not record its array) did not show in any of them. System.Memory defines types and forwards others to CoreLib: it takes the renamed reference twin of #287 (TwinReference.SupportedAssemblies), nothing System.Memory-specific in the compiler |
an ArrayBufferWriter program (1281) 136 376 to 267 264 B (1.96x), a ReadOnlySequence/SequenceReader program (505) 247 040 to 329 736 B (1.33x), the JSON writer sample (310) 649 736 to 723 184 B (1.11x), a MemoryPool program (483) 193 608 to 165 016 B (0.85x); tests/size: regex 875 664 to 894 096 B and regexoptions 2 097 888 to 2 130 616 B (both within their budgets), the other size programs unchanged |
compile cpu 4.1 to 6.7 s (1281), 7.5 to 8.6 s (505), 4.4 to 4.0 s (483), 15.8 to 17.5 s (310) | not measured: no sample has a hot path in these types | 3 146 (Buffers/ReadOnlySequence.cs 2 931, MemoryPool.cs 87, Json/ArrayBufferWriter.cs 88, the EncodingExtensions members of Text/Encoding.cs 40); git diff --shortstat: 1 insertion, 3 146 deletions over 5 files in src |
Flipped (#306). Security: the framework’s own bounds and overflow checks replace the ports’ (ArrayBufferWriter’s growth, which the port once got wrong (#194), SequenceReader’s advance and rewind, ReadOnlySequence’s slicing across segments, EncodingExtensions.GetString decoding a character split across segments); no native code, no unsafe code of csharpc’s. |
memory_throughput: 212 920 / 1 349 448 B; compile cpu 7.7 / 18.0 s; run 116 / 154 ms (0.75x); 0.69 G / 0.88 G instructions |