Skip to content
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

Use fast modulo in HashSet #2143

Closed
wants to merge 3 commits into from
Closed

Use fast modulo in HashSet #2143

wants to merge 3 commits into from

Conversation

eanova
Copy link
Contributor

@eanova eanova commented Jan 24, 2020

This PR addresses #1989

Code changes for fastmodulo version of HashSet. Required CI testing to make sure all builds are working and to check failure at:

src\libraries\System.Diagnostics.Process\tests\ProcessWaitingTests.cs(241,0)

Code changes for fastmodulo
@stephentoub stephentoub changed the title Update HashSet.cs Use fast modulo in HashSet Jan 24, 2020
@@ -1979,6 +2004,14 @@ private int InternalGetHashCode(int hashCode)
return hashCode & Lower31BitMask;
}

#if BIT64
private int FastMod(int value, int divisor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest instead to extract ref int GetBucket(uint hashCode) same as in Dictionary. That puts it in one place, including the #if BIT64 stuff. With [MethodImpl(MethodImplOptions.AggressiveInlining)] on it, as for Dictionary, it will inline and be just as efficient.

@eanova
Copy link
Contributor Author

eanova commented Jan 24, 2020

I think i'd feel more comfortable pushing these changes if there were was better test coverage. A lot of the bugs I found were because of tests outside of System.Collections.

@@ -1979,6 +2004,14 @@ private int InternalGetHashCode(int hashCode)
return hashCode & Lower31BitMask;
}

#if BIT64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that BIT64 works in CoreLib only. Libraries do not have infrastructure for bitness-specific ifdefs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Nuts. You're right.

What do you think of moving HashSet to corelib? It looks like it would not bring a great deal: ISet.cs, HashsetEqualityComparer.cs, BitHelper.cs, and one string.

Or, does JIT inline across assemblies? If so could we call into corelib for GetFastModMultiplier and FastMod -- in 32 bit the multiplier would be passed redundantly and be ignored.

Or, we could abandon this, which would be a pity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be fine with moving the whole System.Collections as part of #2138

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we shouldn't move HashSet in this PR, as part of making this change? Seems like everything would come out in the wash.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We like to avoid no-op refactoring with actual changes.

Copy link
Member

@danmoseley danmoseley Jan 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I should have said is -- just move these 3 types, then follow up by making the change (or in the same PR and not squash)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can start on either one. It would be better if I start on #2138 to get more familiar with the process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danmosemsft I believe the tests are not covering all constructors.

@danmoseley
Copy link
Member

I think i'd feel more comfortable pushing these changes if there were was better test coverage. A lot of the bugs I found were because of tests outside of System.Collections.

That's not good. Are they easy cases to add?

@stephentoub
Copy link
Member

Based on the discussion, it sounds like we should close this until it can be re-done on to of a moved HashSet?

@danmoseley
Copy link
Member

Yes. Too bad.

@danmoseley danmoseley closed this Apr 24, 2020
@danmoseley
Copy link
Member

Thanks @eanova

@eanova
Copy link
Contributor Author

eanova commented Apr 24, 2020

No problem!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants