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

Defer array creation in ConcurrentCache. #72291

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Feb 27, 2024

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner February 27, 2024 19:57
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 27, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as draft February 27, 2024 20:21
// short-lived compilations that do not end up using the cache. As the cache is simple best-effort, it's
// fine if multiple threads end up creating the backing array at the same time. One thread will be last and
// will win, and the others will just end up creating a small piece of garbage that will be collected.
: base(size, createBackingArray: false)
Copy link
Member Author

Choose a reason for hiding this comment

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

i kept this logic only for ConcurrentCache, as it's this cache that says explicitly: expiration policy is "new entry wins over old entry if hashed into the same bucket". So it felt safest to have just for this type. We could move this down to the base if we're ok with this policy for all subclsses.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review March 1, 2024 01:08
@CyrusNajmabadi CyrusNajmabadi changed the title WIP: Defer array creation in ConcurrentCache. Defer array creation in ConcurrentCache. Mar 1, 2024
@CyrusNajmabadi
Copy link
Member Author

Speedometer/DDRITs shows no regressions.

@dotnet/roslyn-compiler for review here. Thanks!

}

public bool TryGetValue(TKey key, [MaybeNullWhen(returnValue: false)] out TValue value)
{
int hash = RuntimeHelpers.GetHashCode(key);
int idx = hash & mask;

var entries = this.entries;
var entries = this.Entries;
Copy link
Contributor

Choose a reason for hiding this comment

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

var entries = this.Entries;

nit: TryGetValue doesn't need to realize the Entries array

Copy link
Member Author

Choose a reason for hiding this comment

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

fair. but this keeps things exactly the same otherwise. something we could consider.

@CyrusNajmabadi
Copy link
Member Author

@dotnet/roslyn-compiler ptal

@CyrusNajmabadi CyrusNajmabadi requested a review from 333fred March 5, 2024 18:10
@CyrusNajmabadi
Copy link
Member Author

@333fred ptal.

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge March 5, 2024 18:31
@CyrusNajmabadi CyrusNajmabadi merged commit e8f4ecb into dotnet:main Mar 5, 2024
24 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the cheapCache2 branch March 5, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants