From d4e1ecc72c5ac47bbeb1f6e1447bb9486b8427fe Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 28 Nov 2017 13:03:19 -0800 Subject: [PATCH] Avoid IEnumerable allocations when flusing data to sqlite. --- .../SQLite/SQLitePersistentStorage_WriteBatching.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorage_WriteBatching.cs b/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorage_WriteBatching.cs index 0301a327e4855..5a09447b90a50 100644 --- a/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorage_WriteBatching.cs +++ b/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorage_WriteBatching.cs @@ -129,8 +129,13 @@ private async Task FlushSpecificWritesAsync( // performed by FlushAllPendingWritesAsync. using (await _writeQueueGate.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { - // Get the writes we need to process. - writesToProcess.AddRange(keyToWriteActions[key]); + // Get the writes we need to process. + // Note: explicitly foreach so we operate on the struct enumerator for + // MultiDictionary.ValueSet. + foreach (var action in keyToWriteActions[key]) + { + writesToProcess.Add(action); + } // and clear them from the queues so we don't process things multiple times. keyToWriteActions.Remove(key);