Comments (13)
ImmutableHashSet.Contains is few times slower that HashSet.Contains
Method | Size | Mean | Error | StdDev | Median | Min | Max | Allocated |
---|---|---|---|---|---|---|---|---|
HashSet | 512 | 5.544 us | 0.1235 us | 0.1155 us | 5.509 us | 5.429 us | 5.843 us | 0 B |
ImmutableHashSet | 512 | 28.264 us | 0.5410 us | 0.5313 us | 28.014 us | 27.777 us | 29.486 us | 0 B |
@jorive @valenis this is quite serious
from performance.
Queue<T>.Enqueue
and Stack<T>.Push
are slower than List<T>.Add
All 3 collections are just wrappers around the Array
so adding an element should be on par.
-f *AddDefaultSize<Int32>.List *AddDefaultSize<Int32>.Stack *AddDefaultSize<Int32>.Queue --join
Method | Count | Mean | Error | StdDev | Median | Min | Max | Gen 0 | Gen 1 | Allocated |
---|---|---|---|---|---|---|---|---|---|---|
List | 512 | 1.352 us | 0.0508 us | 0.0565 us | 1.335 us | 1.300 us | 1.488 us | 0.6822 | 0.0054 | 4.21 KB |
Queue | 512 | 2.213 us | 0.0432 us | 0.0404 us | 2.220 us | 2.151 us | 2.285 us | 0.6779 | 0.0089 | 4.22 KB |
Stack | 512 | 1.478 us | 0.0350 us | 0.0360 us | 1.477 us | 1.423 us | 1.568 us | 0.6815 | 0.0066 | 4.21 KB |
from performance.
ImmutableList.Contains is few times slower that List.Contains or LinkedList.Contains
-f *Contains*List --join
Type | Method | Size | Mean |
---|---|---|---|
ContainsFalse<Int32> | List | 512 | 136.09 us |
ContainsFalse<String> | List | 512 | 1,546.87 us |
ContainsTrue<Int32> | List | 512 | 69.53 us |
ContainsTrue<String> | List | 512 | 769.81 us |
ContainsFalse<Int32> | LinkedList | 512 | 423.52 us |
ContainsFalse<String> | LinkedList | 512 | 2,444.66 us |
ContainsTrue<Int32> | LinkedList | 512 | 214.89 us |
ContainsTrue<String> | LinkedList | 512 | 1,183.79 us |
ContainsFalse<Int32> | ImmutableList | 512 | 13,741.56 us |
ContainsFalse<String> | ImmutableList | 512 | 25,100.01 us |
ContainsTrue<Int32> | ImmutableList | 512 | 6,710.54 us |
ContainsTrue<String> | ImmutableList | 512 | 12,227.36 us |
@jorive @valenis this is quite serious
from performance.
@danmosemsft I created the issues in CoreFX:
https://github.com/dotnet/corefx/issues/36405
https://github.com/dotnet/corefx/issues/36406
https://github.com/dotnet/corefx/issues/36407
https://github.com/dotnet/corefx/issues/36412
https://github.com/dotnet/corefx/issues/36413
https://github.com/dotnet/corefx/issues/36414
https://github.com/dotnet/corefx/issues/36415
https://github.com/dotnet/corefx/issues/36416
We have officially switched to the performance repo in CoreFX so next time I find a performance issue in CoreFX using performance repo I am going to create an issue in CoreFX
from performance.
ConcurrentDictionary.Clear
and ConcurrentQueue.Clear
allocates memory
From the code it looks like it's by design.
where T : Int32
Method | Size | Mean | Allocated |
---|---|---|---|
List | 512 | 0.9614 ns | 0 B |
LinkedList | 512 | 3,070.7609 ns | 0 B |
HashSet | 512 | 2,280.6734 ns | 0 B |
Dictionary | 512 | 2,712.4537 ns | 0 B |
SortedList | 512 | 1.6122 ns | 0 B |
SortedSet | 512 | 5.9412 ns | 0 B |
SortedDictionary | 512 | 15.9420 ns | 0 B |
ConcurrentDictionary | 512 | 30,837.8645 ns | 6480 B |
Stack | 512 | 1.0941 ns | 0 B |
ConcurrentStack | 512 | 2.6410 ns | 0 B |
Queue | 512 | 2.0908 ns | 0 B |
ConcurrentQueue | 512 | 564.8528 ns | 704 B |
Note: 1ns for value types with no nested references is not a bug, the collections do simply array = null
or head = null
and that's it ;)
from performance.
ImmutableDictionary.ContainsKey is few times slower than Dictionary.ContainsKey or even ConcurrentDictionary.ContainsKey
-f *ContainsKey*Dictionary --join
Type | Method | Size | Mean |
---|---|---|---|
ContainsKeyFalse<Int32, Int32> | Dictionary | 512 | 5.625 us |
ContainsKeyFalse<String, String> | Dictionary | 512 | 21.297 us |
ContainsKeyTrue<Int32, Int32> | Dictionary | 512 | 4.208 us |
ContainsKeyTrue<String, String> | Dictionary | 512 | 21.699 us |
ContainsKeyFalse<Int32, Int32> | SortedDictionary | 512 | 57.381 us |
ContainsKeyFalse<String, String> | SortedDictionary | 512 | 759.717 us |
ContainsKeyTrue<Int32, Int32> | SortedDictionary | 512 | 54.232 us |
ContainsKeyTrue<String, String> | SortedDictionary | 512 | 595.410 us |
ContainsKeyFalse<Int32, Int32> | ConcurrentDictionary | 512 | 6.119 us |
ContainsKeyFalse<String, String> | ConcurrentDictionary | 512 | 24.761 us |
ContainsKeyTrue<Int32, Int32> | ConcurrentDictionary | 512 | 6.786 us |
ContainsKeyTrue<String, String> | ConcurrentDictionary | 512 | 26.630 us |
ContainsKeyFalse<Int32, Int32> | ImmutableDictionary | 512 | 27.467 us |
ContainsKeyFalse<String, String> | ImmutableDictionary | 512 | 51.890 us |
ContainsKeyTrue<Int32, Int32> | ImmutableDictionary | 512 | 32.160 us |
ContainsKeyTrue<String, String> | ImmutableDictionary | 512 | 74.269 us |
ContainsKeyFalse<Int32, Int32> | ImmutableSortedDictionary | 512 | 36.849 us |
ContainsKeyFalse<String, String> | ImmutableSortedDictionary | 512 | 665.937 us |
ContainsKeyTrue<Int32, Int32> | ImmutableSortedDictionary | 512 | 27.833 us |
ContainsKeyTrue<String, String> | ImmutableSortedDictionary | 512 | 523.075 us |
@jorive @valenis another perf issue with immutable collections
from performance.
Creating ImmutableDictionary from an existing dictionary is very slow
-f *CtorFromCollection*Dictionary --join
Type | Method | Size | Mean | Allocated |
---|---|---|---|---|
CtorFromCollection<Int32> | Dictionary | 512 | 7.973 us | 10.3 KB |
CtorFromCollection<String> | Dictionary | 512 | 24.017 us | 14.38 KB |
CtorFromCollection<Int32> | SortedDictionary | 512 | 80.160 us | 24.16 KB |
CtorFromCollection<String> | SortedDictionary | 512 | 716.357 us | 28.17 KB |
CtorFromCollection<Int32> | ConcurrentDictionary | 512 | 66.370 us | 122.36 KB |
CtorFromCollection<String> | ConcurrentDictionary | 512 | 137.390 us | 135.45 KB |
CtorFromCollection<Int32> | ImmutableDictionary | 512 | 226.620 us | 28.09 KB |
CtorFromCollection<String> | ImmutableDictionary | 512 | 344.186 us | 32.09 KB |
CtorFromCollection<Int32> | ImmutableSortedDictionary | 512 | 101.518 us | 52.58 KB |
CtorFromCollection<String> | ImmutableSortedDictionary | 512 | 716.851 us | 64.59 KB |
@jorive @valenis another perf issue with immutable collections
from performance.
Creating ImmutableHashSet from an existing collection is very slow
-f *CtorFromCollection*HashSet --join
Type | Method | Size | Mean | Allocated |
---|---|---|---|---|
CtorFromCollection<Int32> | HashSet | 512 | 11.41 us | 8.29 KB |
CtorFromCollection<String> | HashSet | 512 | 28.68 us | 10.32 KB |
CtorFromCollection<Int32> | ImmutableHashSet | 512 | 173.34 us | 28.08 KB |
CtorFromCollection<String> | ImmutableHashSet | 512 | 260.43 us | 28.08 KB |
another perf issue with immutable collections
from performance.
Creating Stack and Queue takes slighly more time than creating List
All 3 collections are just wrappers around the Array so creating them should be on par.
Type | Method | Size | Mean | Allocated |
---|---|---|---|---|
CtorGivenSize<Int32> | Array | 512 | 114.9 ns | 2.02 KB |
CtorGivenSize<String> | Array | 512 | 229.2 ns | 4.02 KB |
CtorGivenSize<Int32> | List | 512 | 117.2 ns | 2.06 KB |
CtorGivenSize<String> | List | 512 | 237.4 ns | 4.06 KB |
CtorGivenSize<Int32> | Queue | 512 | 119.7 ns | 2.07 KB |
CtorGivenSize<String> | Queue | 512 | 270.5 ns | 4.07 KB |
CtorGivenSize<Int32> | Stack | 512 | 123.3 ns | 2.06 KB |
CtorGivenSize<String> | Stack | 512 | 257.5 ns | 4.06 KB |
from performance.
Indexer.Set of List is much slower than Array
[Benchmark]
public T[] Array()
{
var array = _array;
for (int i = 0; i < array.Length; i++)
array[i] = default;
return array;
}
[Benchmark]
public List<T> List()
{
var list = _list;
for (int i = 0; i < list.Count; i++)
list[i] = default;
return list;
}
-f *IndexerSet*.List *IndexerSet*.Array --join
Type | Method | Size | Mean |
---|---|---|---|
IndexerSet<Int32> | Array | 512 | 186.7 ns |
IndexerSet<String> | Array | 512 | 187.1 ns |
IndexerSet<Int32> | List | 512 | 974.8 ns |
IndexerSet<String> | List | 512 | 901.1 ns |
from performance.
Iterating with ForEach over Immutable collections is very slow
Method | Size | Mean | StdDev | Allocated |
---|---|---|---|---|
Array | 512 | 211.6 ns | 1.245 ns | 0 B |
List | 512 | 2,009.2 ns | 46.177 ns | 0 B |
LinkedList | 512 | 3,646.2 ns | 62.494 ns | 0 B |
HashSet | 512 | 2,388.7 ns | 14.854 ns | 0 B |
Dictionary | 512 | 2,702.9 ns | 42.443 ns | 0 B |
Queue | 512 | 3,931.8 ns | 85.241 ns | 0 B |
Stack | 512 | 4,003.1 ns | 165.352 ns | 0 B |
SortedList | 512 | 10,709.4 ns | 73.401 ns | 56 B |
SortedSet | 512 | 12,465.8 ns | 316.782 ns | 224 B |
SortedDictionary | 512 | 18,707.2 ns | 560.691 ns | 224 B |
ConcurrentDictionary | 512 | 29,045.2 ns | 233.732 ns | 64 B |
ConcurrentQueue | 512 | 5,568.0 ns | 20.909 ns | 80 B |
ConcurrentStack | 512 | 4,846.1 ns | 131.191 ns | 48 B |
ConcurrentBag | 512 | 5,659.3 ns | 119.693 ns | 4160 B |
ImmutableArray | 512 | 1,123.0 ns | 22.989 ns | 0 B |
ImmutableDictionary | 512 | 109,210.6 ns | 3,377.835 ns | 0 B |
ImmutableHashSet | 512 | 118,605.7 ns | 1,287.016 ns | 0 B |
ImmutableList | 512 | 43,822.9 ns | 2,535.575 ns | 0 B |
ImmutableQueue | 512 | 5,311.1 ns | 53.010 ns | 0 B |
ImmutableStack | 512 | 4,659.0 ns | 90.869 ns | 0 B |
ImmutableSortedDictionary | 512 | 51,982.4 ns | 902.699 ns | 0 B |
ImmutableSortedSet | 512 | 46,628.9 ns | 1,373.656 ns | 0 B |
foreach over Array is implemented in CLR to match for loop with the performance, I wonder how much effor would it cost to add similar support for ImmutableArray
from performance.
@adamsitnik nice findings! :) … I'm surprised by those huge differences in such a trivial scenarios.
from performance.
What to do here -- seems to me each of these findings could become an issue in CoreFX perhaps for community interest, then we coud close this?
from performance.
Related Issues (20)
- Provide blob with JSON data for auto filed issues HOT 1
- Maui iOS Net9.0 Podcast failing
- Add device version to PowerBI chart HOT 1
- Move secret synchronize job out of performance repo
- Setup affinity for Windows Ampere runs HOT 2
- Investigate ToString Methods
- [GC.Infrastructure] More robustness changes for ASP.NET benchmark runs.
- Wasm runs failing with empty WasmAssembliesToBundle HOT 10
- Readd Microsoft.NET.Test.Sdk package reference HOT 3
- Perf_Regex_Industry_SliceSlice.Count Benchmarks OOM under public CI with `[MemoryRandomization]`
- 8.0 Perf CI Runs Failing
- [GC Infrastructure] Same output directory as ASP.NET Benchmarks for GCPerfSim
- Android BDN test runs are failing
- WinHttpHandler
- Some MonoAOT BDN individual tests are failing with PlatformNotSupportedException HOT 4
- Performance triage improvements in .NET 9
- Two Perf_Regex_Common tests crashing in MonoAOT testing
- Add ADX query for Mono and WASM issues
- Cannot set --affinity option for 32+ CPUs HOT 2
- Report caches don't account for test names that match past 200 characters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from performance.