Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d005a66
sketch out improved ParallelPrefetcher; focus is on reducing allocati…
kevin-montrose Mar 14, 2024
14d5a0f
little more cleanup to further reduce allocations, and save a tiny am…
kevin-montrose Mar 15, 2024
dd7bbae
start on testing
kevin-montrose Mar 18, 2024
7032e9c
some tweaks and testing for buffer management
kevin-montrose Mar 18, 2024
6868904
test exception handling; fix a bug in high concurrency case that woul…
kevin-montrose Mar 18, 2024
7086198
test cancellation
kevin-montrose Mar 18, 2024
91eca90
more testing, a little bit of cleanup
kevin-montrose Mar 18, 2024
afe77d2
test the case where the enumerator faults; fixes a couple leaks of Ta…
kevin-montrose Mar 18, 2024
a7e0012
tiny bit of cleanup
kevin-montrose Mar 18, 2024
354b22e
cleanup and expand comments; code is tricky, it needs documentation
kevin-montrose Mar 18, 2024
e0ed9f9
address a whole bunch of style nits, just to keep compiler Message co…
kevin-montrose Mar 19, 2024
b972b0a
address some feedback on comment clarity
kevin-montrose Mar 20, 2024
8ade43b
don't rely on finalizers for testing, it's too brittle; hold up was n…
kevin-montrose Mar 20, 2024
dedbd20
complete ITrace proxy for testing
kevin-montrose Mar 20, 2024
4cdd081
style nits and a bit more commentary
kevin-montrose Mar 20, 2024
f6c3993
explicit test for concurrent access to the inner IEnumerator
kevin-montrose Mar 20, 2024
fa5b42a
explicit test that IEnumerator is disposed
kevin-montrose Mar 20, 2024
9e46e1b
explicitly implement all ITrace members
kevin-montrose Mar 20, 2024
2838a8d
Merge branch 'master' into parallelPrefetchRework
neildsh Mar 28, 2024
31cb07c
address feedback: internal class members should be public or private
kevin-montrose Mar 29, 2024
f52a737
address feedback: break test-only bits of ParallelPrefetch out into a…
kevin-montrose Mar 29, 2024
e0891fb
address feedback: move const above type declarations
kevin-montrose Mar 29, 2024
f7465e0
address feedback: naming nits
kevin-montrose Mar 29, 2024
acdb020
address feedback: use the existing NoOpTrace
kevin-montrose Mar 29, 2024
987c33d
address feedback: remove pointless using
kevin-montrose Mar 29, 2024
cc4f82d
Merge branch 'master' into parallelPrefetchRework
neildsh Mar 29, 2024
75e5d0b
Merge branch 'master' into parallelPrefetchRework
kevin-montrose Mar 29, 2024
b5d4f07
update baseline trace text for QueryAsync test
kevin-montrose Mar 29, 2024
4147878
Merge branch 'master' into parallelPrefetchRework
neildsh Apr 1, 2024
e8f0cca
Merge branch 'master' into parallelPrefetchRework
neildsh Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
little more cleanup to further reduce allocations, and save a tiny am…
…ount of CPU
  • Loading branch information
kevin-montrose committed Mar 15, 2024
commit 14d5a0fae0acff7f012c003ae616f64ea3295436
23 changes: 14 additions & 9 deletions Microsoft.Azure.Cosmos/src/Pagination/ParallelPrefetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ internal static class ParallelPrefetch
/// </summary>
private sealed class CommonPrefetchState
{
private bool finishedEnumerating;
// we also use this to signal if we're finished enumerating, to save space
private IEnumerator<IPrefetcher> enumerator;

/// <summary>
/// If this is true, it's a signal that new work should not be queued up.
/// </summary>
internal bool FinishedEnumerating
Comment thread
kevin-montrose marked this conversation as resolved.
Outdated
=> Volatile.Read(ref this.finishedEnumerating);
=> Volatile.Read(ref this.enumerator) == null;

/// <summary>
/// Common <see cref="ITrace"/> to be used by all tasks.
Expand All @@ -40,8 +41,11 @@ internal bool FinishedEnumerating
/// to use.
///
/// Once at least once Task been started, should only be accessed under a lock.
///
/// If <see cref="FinishedEnumerating"/> == true, this returns null.
/// </summary>
internal IEnumerator<IPrefetcher> Enumerator { get; private set; }
internal IEnumerator<IPrefetcher> Enumerator
=> Volatile.Read(ref this.enumerator);

/// <summary>
/// <see cref="CancellationToken"/> provided via <see cref="PrefetchInParallelAsync(IEnumerable{IPrefetcher}, int, ITrace, CancellationToken)"/>.
Expand All @@ -51,7 +55,7 @@ internal bool FinishedEnumerating
internal CommonPrefetchState(ITrace prefetchTrace, IEnumerator<IPrefetcher> enumerator, CancellationToken cancellationToken)
{
this.PrefetchTrace = prefetchTrace;
this.Enumerator = enumerator;
this.enumerator = enumerator;
this.CancellationToken = cancellationToken;
}

Expand All @@ -60,7 +64,7 @@ internal CommonPrefetchState(ITrace prefetchTrace, IEnumerator<IPrefetcher> enum
/// </summary>
internal void SetFinishedEnumerating()
{
Volatile.Write(ref this.finishedEnumerating, true);
Volatile.Write(ref this.enumerator, null);
}
}

Expand Down Expand Up @@ -207,7 +211,6 @@ static async (context) =>
SinglePrefetchState innerState = (SinglePrefetchState)context;

CommonPrefetchState innerCommonState = innerState.CommonState;
IEnumerator<IPrefetcher> e = innerCommonState.Enumerator;

if (innerCommonState.FinishedEnumerating)
{
Expand All @@ -222,8 +225,10 @@ static async (context) =>
// e.MoveNext()
lock (innerCommonState)
{
// ... but check again, the answer might have changed while we go the lock
if (innerCommonState.FinishedEnumerating)
// this can have transitioned to null since we last checked
// so this is basically double-check locking
IEnumerator<IPrefetcher> e = innerCommonState.Enumerator;
Comment thread
kevin-montrose marked this conversation as resolved.
Outdated
if (e == null)
{
return;
}
Expand Down Expand Up @@ -555,7 +560,7 @@ private static async Task HighConcurrencyPrefetchInParallelAsync(IEnumerable<IPr
if (toAwait == null)
{
// hand the last of the arrays back
ReturnRentedArray(runningTasks, runningTasks.Length);
ReturnRentedArray(runningTasks, toAwaitIndex);
runningTasks = null;

break;
Expand Down