Skip to content

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

Merged
heejaechang merged 2 commits intodotnet:masterfrom
heejaechang:poolIncrementalHash
Feb 20, 2019
Merged

pool incrementalHash so that we don't create one unnecessarily#33496
heejaechang merged 2 commits intodotnet:masterfrom
heejaechang:poolIncrementalHash

Conversation

@heejaechang
Copy link
Copy Markdown
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
// all these are just helper methods
internal partial class Checksum
{
private static readonly ObjectPool<IncrementalHash> s_objectPool =
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor Author

tagging @dotnet/roslyn-ide

internal partial class Checksum
{
private static readonly ObjectPool<IncrementalHash> s_incrementalHashPool =
new ObjectPool<IncrementalHash>(() => IncrementalHash.CreateHash(HashAlgorithmName.SHA1), size: 20);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why 20?

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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