Skip to content

Add fast path for Overlaps when other is HashSet with same equality comparer and has more items - #132763

Open
Advitalitum wants to merge 1 commit into
dotnet:mainfrom
Advitalitum:main
Open

Add fast path for Overlaps when other is HashSet with same equality comparer and has more items#132763
Advitalitum wants to merge 1 commit into
dotnet:mainfrom
Advitalitum:main

Conversation

@Advitalitum

Copy link
Copy Markdown

What do you think about this optimization?

@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 25, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

@eiriktsarpalis

Copy link
Copy Markdown
Member

@EgorBot -linux_amd -osx_arm64

usingSystem.Collections.Generic;usingSystem.Linq;usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(Benchmarks).Assembly).Run(args);[MemoryDiagnoser]publicclassBenchmarks{privateHashSet<int>_set=null!;privateIEnumerable<int>_largerDisjointHashSet=null!;privateIEnumerable<int>_largerHashSetWithLateMatch=null!;privateIEnumerable<int>_listWithImmediateMatch=null!;privateIEnumerable<int>_largerDisjointList=null!;[GlobalSetup]publicvoidSetup(){_set=newHashSet<int>(Enumerable.Range(0,100));_largerDisjointHashSet=newHashSet<int>(Enumerable.Range(100,10_000));HashSet<int>largerHashSetWithLateMatch=new(Enumerable.Range(100,9_999));largerHashSetWithLateMatch.Add(0);_largerHashSetWithLateMatch=largerHashSetWithLateMatch;_listWithImmediateMatch=newList<int>{0};_largerDisjointList=newList<int>(Enumerable.Range(100,10_000));}[Benchmark]publicboolLargerHashSet_Disjoint()=>_set.Overlaps(_largerDisjointHashSet);[Benchmark]publicboolLargerHashSet_MatchLastInOther()=>_set.Overlaps(_largerHashSetWithLateMatch);[Benchmark]publicboolList_MatchFirst()=>_set.Overlaps(_listWithImmediateMatch);[Benchmark]publicboolLargerList_Disjoint()=>_set.Overlaps(_largerDisjointList);}

Note

This benchmark request was generated with GitHub Copilot.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Collectionscommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Advitalitum@eiriktsarpalis