csharpc

System.Collections.ArrayList and BitArray

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.ArrayList and System.Collections.BitArray (src/Csharpc/upstream-types/System.Collections.ArrayList.txt, System.Collections.BitArray.txt, #372) 516 (ArrayList), 662 (BitArray), 1104, 1160, 1312 and the rest of the collections set byte-identical at -O0, -O2, via IL and on wasm32. New samples recorded from .NET: 1343 (the untyped Array.IndexOf/LastIndexOf/Sort(Array, int, int, IComparer) on object[], string[], int[], double[] with NaN and -0.0, enum and struct arrays, every argument check, and ArrayList’s IndexOf/LastIndexOf/Sort/BinarySearch, ranged and through Adapter/FixedSize/ReadOnly/GetRange; the base compiler does not compile it: Array.IndexOf(Array, object) “on a non-array argument”) and 1344 (BitArray over 1 to 1 000 bits: construction from bool[], And/Or/Xor/Not with partial last words, CopyTo bool[]/byte[]/int[], shifts, Length changes) 516: 491 208 / 321 000 B; 662: 254 376 / 230 840 B; arraylist_bitarray_throughput 235 096 / 179 160 B (upstream’s ArrayList wrappers and BitArray’s vector paths) 516: 11.2 / 12.5 s; 662: 6.4 / 6.0 s arraylist_bitarray_throughput (ArrayList Add/IndexOf/Contains/Sort/BinarySearch/RemoveAt over boxed ints, BitArray construction, logic, shifts and CopyTo over 4 096 bits): 18 567 M / 36 808 M instructions (0.50x), median of 5 1 794 / 4 481 ms 944 (corelib/ArrayList.cs, ArrayListAdapter.cs, BitArray.cs) From IL, flipped; shadows deleted. General pieces: (1) the untyped Array.IndexOf(Array, object[, int[, int]]), LastIndexOf and Sort(Array, int, int, IComparer) for an element type known only at run time (corelib/ArrayExtras.cs), with .NET’s checks in its order and messages; the result is the first element for which element.Equals(value) holds, which is what every one of .NET’s paths computes; (2) RankException from Sort/BinarySearch/IndexOf of a multi-dimensional array now carries .NET’s text (“Only single dimension arrays are supported here.”; the corelib said “…dimensional arrays are supported for the requested action.”); (3) Vector64/256/512<T>.Count are constants (their IsHardwareAccelerated stays false), and a constrained call on any interface Vector128<T> implements (IBitwiseOperators<...>.op_BitwiseAnd in BitArray’s generic helpers) is the vector’s own member. Security: BitArray’s vector loops are upstream’s, bounded by the int-array length it allocates (GetInt32ArrayLengthFromBitLength); the untyped Array members read elements through GetValue (bounds-checked). arraylist_bitarray_throughput: 234 856 / 1 452 800 B; compile cpu 5.9 / 17.5 s; run 1 828 / 1 834 ms (1.00x); 18.57 G / 18.42 G instructions (1.01x)