-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some additional micro benchmark coverage for immutable collections. #2268
Add some additional micro benchmark coverage for immutable collections. #2268
Conversation
@adamsitnik maybe can give feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@madelson big thanks for your contribution! Please take a look at my comments.
src/benchmarks/micro/libraries/System.Collections/AddRemove/AddRemoveSteadyState.cs
Outdated
Show resolved
Hide resolved
src/benchmarks/micro/libraries/System.Collections/AddRemove/AddRemoveSteadyState.cs
Outdated
Show resolved
Hide resolved
@@ -3,6 +3,7 @@ | |||
// See the LICENSE file in the project root for more information. | |||
|
|||
using System.Collections.Generic; | |||
using System.Collections.Immutable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the existing benchmarks that you can find in this file has been added in #938 to validate dotnet/coreclr#27299 which required a very specific benchmark coverage of the Dictionary<TKey, Value>
APIs. We don't need such detailed coverage for other dictionary types as they already have good overall coverage. Please revert all the changes in this file.
src/benchmarks/micro/libraries/System.Collections/AddRemove/AddRemoveSteadyState.cs
Outdated
Show resolved
Hide resolved
@@ -133,5 +134,71 @@ public ObservableCollection<T> ObservableCollection() | |||
} | |||
return collection; | |||
} | |||
|
|||
[Benchmark] | |||
public ImmutableArray<T> ImmutableArray() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These benchmarks overall look good, but we should move them out of this class. This class is called AddGivenSize because it tests adding new items to collections that support specifying initial capacity. Like new List<T>(Size)
. We had benchmarks for AddDefaultSize
(added in #92), but we have later decided to redesign them to CreateAddAndClear
(#663) so they can also cover Clear
. Please move the new benchmarks from this type to CreateAddAndClear
and add a Clear
method invocation to them.
Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
@adamsitnik quickly reviewing the remaining benchmarks, I see the following places where we could add additional immutable collections coverage. Are any of these of interest? TryAddDefaultSize
AddRemoveFromDifferentThreads/SameThread
Perf_Dictionary
IndexerSet
Perf_SortedSet
CopyTo
CreateAddAndRemove
Sort
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @madelson !
src/benchmarks/micro/libraries/System.Collections/Add/AddGivenSize.cs
Outdated
Show resolved
Hide resolved
It's a good idea to add these (I was not aware of the existence of the
The original benchmarks are quite noisy (source): and I am not sure whether we should promote immutable collections for multi-threaded mutable use cases (cc @stephentoub). I would rather say no.
The
the immutable collections are throwing for mutable methods: and in general we are not benchmarking edge case scenarios like this (https://github.com/dotnet/performance/blob/main/docs/microbenchmark-design-guidelines.md#benchmarks-are-not-unit-tests)
It's a good idea to create similar type for ImmutableSortedSet
👍 @madelson I am going to merge this PR, please send more benchmarks in new PRs. Thank you for your contribution! |
Thanks @adamsitnik !
Sorry I should have clarified. The useful equivalent of indexer set for immutable collections is the
As mentioend there is the |
See dotnet/runtime#14477 (comment) for context.
Adding these additional benchmarks will obviously have runtime cost, so I wanted to start with just adding immutable collections benchmarks to a few files to get some feedback / a sense of whether or not this is the intended direction.