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

pool incrementalHash so that we don't create one unnecessarily #33496

Merged
merged 2 commits into from
Feb 20, 2019

Conversation

heejaechang
Copy link
Contributor

save cost of creating new incremental hash.

@heejaechang heejaechang requested a review from a team as a code owner February 19, 2019 22:25
@@ -14,41 +15,44 @@ namespace Microsoft.CodeAnalysis
// all these are just helper methods
internal partial class Checksum
{
private static readonly ObjectPool<IncrementalHash> s_objectPool =
Copy link
Member

Choose a reason for hiding this comment

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

💡 Consider using a more specific name for this pool field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure.

@heejaechang
Copy link
Contributor Author

tagging @dotnet/roslyn-ide

@@ -14,41 +15,44 @@ namespace Microsoft.CodeAnalysis
// all these are just helper methods
internal partial class Checksum
{
private static readonly ObjectPool<IncrementalHash> s_incrementalHashPool =
new ObjectPool<IncrementalHash>(() => IncrementalHash.CreateHash(HashAlgorithmName.SHA1), size: 20);
Copy link
Member

Choose a reason for hiding this comment

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

why 20?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no particular reason. other pool uses 20 so, it uses 20 as well.

stream.Seek(0, SeekOrigin.Begin);
stream.Seek(0, SeekOrigin.Begin);

var hash = pooledHash.Object;
Copy link
Member

Choose a reason for hiding this comment

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

does anything need to reset this, either before/after using it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hash got reset when it get into the pool

@heejaechang heejaechang merged commit ecdcd95 into dotnet:master Feb 20, 2019
@sharwell sharwell mentioned this pull request Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants