Add overload for creating Set/Map that includes an IComparer<'T>
I propose we add an overload for the creation of Set<'T> and Map<'K, 'V> which takes an IComparer<'T> to override the default comparison behavior of these two collections. Where I believe this would add the most value is in the case of structs that currently get boxed during comparison leading to performance degradation.
The existing way of approaching this problem in F# is to use the built-in comparison functionality in the F# language.
You can see from the benchmarks in this repo. The Struct and CustomStruct versions are allocating more memory than the default Record.
| Method |
Mean |
Error |
StdDev |
Gen 0 |
Allocated |
| Record |
2.464 us |
0.0479 us |
0.0774 us |
0.4044 |
3 KB |
| StructRecord |
2.508 us |
0.0500 us |
0.0748 us |
0.7248 |
6 KB |
| CustomStructRecord |
3.798 us |
0.0758 us |
0.0811 us |
0.8926 |
7 KB |
If this proposal does not address the GC/performance problem then I suggest we discard it since it is the main concern.
Pros and Cons
The advantages of making this adjustment to F# are that we reduce the GC associated with boxing structs unnecessarily.
The disadvantages of making this adjustment to F# are added complexity of the F# Core library and therefore more code to maintain.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
Add overload for creating Set/Map that includes an IComparer<'T>
I propose we add an overload for the creation of
Set<'T>andMap<'K, 'V>which takes anIComparer<'T>to override the default comparison behavior of these two collections. Where I believe this would add the most value is in the case of structs that currently get boxed during comparison leading to performance degradation.The existing way of approaching this problem in F# is to use the built-in comparison functionality in the F# language.
You can see from the benchmarks in this repo. The
StructandCustomStructversions are allocating more memory than the default Record.If this proposal does not address the GC/performance problem then I suggest we discard it since it is the main concern.
Pros and Cons
The advantages of making this adjustment to F# are that we reduce the GC associated with boxing structs unnecessarily.
The disadvantages of making this adjustment to F# are added complexity of the F# Core library and therefore more code to maintain.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.