csharpc

System.Collections

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.Collections + System.Collections.Concurrent (System.Collections,System.Collections.Concurrent) 16 of 16 samples that both routes compile are byte-identical to real .NET in the A/B (the Stack/LinkedList/Sorted*/PriorityQueue/OrderedDictionary samples, BlockingCollection (threads, members), ConcurrentBag/Stack/Queue, Partitioner, Parallel.*, PLINQ); after the flip also at -O0 and -O2 (56 runs). Security (threads): the shadows of BlockingCollection (a port of the upstream code over SemaphoreSlim) and ConcurrentStack (the upstream CAS loop) had the same logic; ConcurrentBag was a one-lock simplification and is now upstream’s per-thread lists with work stealing. What those rely on survives in the IL lowering: volatile. and volatile fields are acquire loads / release stores, Interlocked.* are sequentially consistent LLVM atomics, Thread.MemoryBarrier is a seq_cst fence, ThreadLocal<T> and lock are the corelib’s. Checked by the producer/consumer, bag, stack and partitioner samples (443, 544, 1031, 1032, 550, 632) and the contended throughput program, whose checksum (sums and counts independent of scheduling) was equal to real .NET on every run 1.12x over 16 samples (10 341 against 9 222 KB); 1.39x over the six samples with a shadow comparison at 5 runs; the throughput programs 353 to 492 KB (concurrent), 159 to 285 KB (collections) 1.13x (300 against 266 CPU s over 16 samples) concurrent program 1.15x slower (801 to 919 ms, contention-bound); collections program 0.07x (20 603 ms to 1 400 ms: the shadows’ SortedList/LinkedList paths were quadratic) 5 977 (the Collections.cs shadows without Queue<T>, OrderedDictionary.cs, StructuralComparisons.cs, Concurrent/{BlockingCollection,ConcurrentBag,ConcurrentStack,Partitioner}.cs) Flipped (#271, #275). The framework-IL choice always takes System.Collections, System.Collections.Concurrent and System.Collections.NonGeneric (the corelib’s Parallel, SemaphoreSlim and JSON shadows build on them); tests/size hello and the other programs are unchanged. CoreLib’s internal string-comparer family, named by OrderedDictionary, is served by the corelib’s types of the same shape. collections_asm_throughput: 234 328 / 1 374 304 B; compile cpu 14.2 / 13.9 s; run 1 383 / 2 637 ms (0.52x); 12.26 G / 19.12 G instructions; concurrent_throughput: 483 512 / 1 892 616 B; compile cpu 17.0 / 25.8 s; run 1 092 / 643 ms (1.70x); 1.08 G / 1.07 G instructions