csharpc

System.Collections.Concurrent (CoreLib part)

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)
ConcurrentDictionary<TKey,TValue> and ConcurrentQueue<T> (src/Csharpc/upstream-types/System.Collections.Concurrent.txt, CoreLib types: the slicer route; #399) 15 samples that use them (442 the dictionary’s enumeration order, 632 the queue’s segments, 847 AlternateLookup<ReadOnlySpan<char>> under the default, Ordinal and OrdinalIgnoreCase comparers, BlockingCollection over the queue 544/1030/1031/641, Partitioner, PLINQ, HttpClient 1000/1005, and the slices’ stress sample 1325) and the new 1329 byte-identical to real .NET at -O0, -O2 and via IL; on wasm32 the ones that need no threads or sockets (442, 632, 847, 1030, 1032, 1321, 1325, 1329), from the 32-bit slice (#382: the dictionary’s IsWriteAtomic and GetBucket are compiled differently there, Slicer pointer-size); tests/slicer.sh 11 of 11 concurrent_dictionary_throughput 208 976 to 209 200 B (+224); before the GetTypeCode fold 450 488 B. The 12 size budgets unchanged 6.4 to 6.7 s cpu (NativeAOT publish 14.8 to 16.4 s) concurrent_dictionary_throughput (tools/il-first/bench, CD int and string keys on four threads, then a queue filled and drained by four threads each; the drain stops at the first failed TryDequeue, so no thread spins and the count is steady), callgrind: 2.803 G to 2.810 G instructions (+0.26 %, the order of the run-to-run spread of CAS retries); median of 7: 628 to 760 ms, NativeAOT 594 and 767 ms in the same windows (a loaded host: the ratio is the steady figure, 1.06x to 0.99x) 3 571 (corelib/Concurrent/ConcurrentDictionary.cs 2 649, ConcurrentQueue.cs 922); 77 added to corelib/UpstreamSupport.cs (the span and OrdinalIgnoreCase non-randomized hashes the contract’s string comparer used from the deleted file) From IL; both shadows deleted. Compiler fixes it needed, both general: the slicer copies [AsyncStateMachine]/[IteratorStateMachine]/[AsyncIteratorStateMachine] (the #345 guard stopped on ConcurrentQueue<T>.Enumerate; stack traces name a state machine’s frame after the method that carries one), and the IL front-end folds Type.GetTypeCode(typeof(X)) for a known value type or string to a constant (as ILCompiler does; 1329 checks every code against .NET). Without the fold, IsWriteAtomic’s switch on Type.GetTypeCode(typeof(TValue)) called the run-time reflection lookup, which keeps every boxed BCL value’s formatting: the program was 450 488 B. Security (threads): what the upstream code relies on survives in the IL lowering, as for the rest of System.Collections.Concurrent (docs/il-first/System.Collections.md): volatile. and volatile fields are acquire loads / release stores (the dictionary’s VolatileNode buckets and _budget, the queue segment’s slot sequence numbers and PaddedHeadAndTail), Interlocked.* are sequentially consistent LLVM atomics (the queue’s head/tail CAS), Monitor/lock are the corelib’s (the dictionary’s striped locks, the queue’s cross-segment lock). String keys keep the attacker-resistant rehash: the contract’s UpstreamNonRandomizedStringEqualityComparer switches to the Marvin-seeded comparer after 100 collisions, as Dictionary does. The throughput program’s checksum (sums and counts independent of scheduling) is equal under real .NET on every run and equal between csharpc and NativeAOT in every measurement (measure-aot.sh checks it) concurrent_dictionary_throughput: 209 200 / 1 395 112 B; compile cpu 6.7 / 14.8 s; run 760 / 767 ms (0.99x, was 1.06x with the shadows); 2.81 G / 3.11 G instructions (0.90x). concurrent_throughput (BlockingCollection over the queue, Bag, Stack, Partitioner; #350) unchanged by the flip: 495 992 B both, 1.07 / 1.12 G instructions; its run time, 2.7x to 3.6x NativeAOT’s between runs on this host, is off-CPU (blocking hand-offs) and stays #350’s