-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Switch to value-tasks in a few oop syncing points. #63056
Conversation
{ | ||
Debug.Assert(!checksums.Contains(Checksum.Null)); | ||
if (checksums.Count == 0) | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a core change/thing i noticed. When logging this information. we call into this tons of times with nothing to actually sync. Roughly 98%+ of the time this happens. so this can insta-bail. Which allows this to sensibly be a value task. the rest is just bubbling that upwards for all calls that themselves are just calling awaiting value-task helpers.
@@ -52,24 +52,22 @@ public override async Task<T> GetAssetAsync<T>(Checksum checksum, CancellationTo | |||
} | |||
} | |||
|
|||
public async Task<List<ValueTuple<Checksum, T>>> GetAssetsAsync<T>(IEnumerable<Checksum> checksums, CancellationToken cancellationToken) | |||
public async ValueTask<ImmutableArray<ValueTuple<Checksum, T>>> GetAssetsAsync<T>(HashSet<Checksum> checksums, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing items with known length allows us to optimize more (both by bailing out early and by getting the right sized immutable collections to return).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use an Immutable type here?
b130bfa
to
658dad5
Compare
658dad5
to
72c22c5
Compare
accc866
to
77180d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall lgtm
public override Task<T> GetAssetAsync<T>(Checksum checksum, CancellationToken cancellationToken) | ||
=> _validator.GetValueAsync<T>(checksum); | ||
public override async ValueTask<T> GetAssetAsync<T>(Checksum checksum, CancellationToken cancellationToken) | ||
=> await _validator.GetValueAsync<T>(checksum).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓why do we await here instead of just returning the value task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because _validator.GetValueAsync returns a Task, nto a ValueTask. This is a simple way to map between them.
@@ -52,24 +52,22 @@ public override async Task<T> GetAssetAsync<T>(Checksum checksum, CancellationTo | |||
} | |||
} | |||
|
|||
public async Task<List<ValueTuple<Checksum, T>>> GetAssetsAsync<T>(IEnumerable<Checksum> checksums, CancellationToken cancellationToken) | |||
public async ValueTask<ImmutableArray<ValueTuple<Checksum, T>>> GetAssetsAsync<T>(HashSet<Checksum> checksums, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use an Immutable type here?
On the input side, no. THese are effectively 'scratch' sets where we're computing work to do, doing the work, then returning the scratch sets to the pool. Think of them as the 'set' equivalent to passing around work with a temporary ArrayBuilder. We want to avoid the unnecessary conversion of this to an immutable array as we're not ever storing this. |
Noticed while profiling this area.
I recommend reviewing one commit at a time.