Skip to content

Commit e81e178

Browse files
authored
Merge pull request #328 from microsoft/bugfix/backing-store-perf
fix: performance issue with InMemoryBackingStore
2 parents b924784 + b5f3635 commit e81e178

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.11.2] - 2024-08-14
11+
12+
### Changed
13+
14+
- Fixed an additional performance regression with the backing store introduced in version 1.9.2 by #243
15+
1016
## [1.11.1] - 2024-08-12
1117

1218
### Changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<!-- Common default project properties for ALL projects-->
33
<PropertyGroup>
4-
<VersionPrefix>1.11.1</VersionPrefix>
4+
<VersionPrefix>1.11.2</VersionPrefix>
55
<VersionSuffix></VersionSuffix>
66
<!-- This is overidden in test projects by setting to true-->
77
<IsTestProject>false</IsTestProject>

src/abstractions/store/InMemoryBackingStore.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ public void Set<T>(string key, T? value)
8181
// All the list items are dirty as the model has been touched.
8282
foreach(var item in collectionValues)
8383
{
84-
if(item is IBackedModel model)
84+
// we don't support heterogeneous collections, so we can break if the first item is not a IBackedModel
85+
if(item is not IBackedModel model) break;
86+
model.BackingStore.InitializationCompleted = false;
87+
model.BackingStore.Subscribe((keyString, oldObject, newObject) =>
8588
{
86-
model.BackingStore.InitializationCompleted = false;
87-
model.BackingStore.Subscribe((keyString, oldObject, newObject) =>
88-
{
89-
Set(key, value);
90-
}, key); // use property name(key) as subscriptionId to prevent excess subscription creation in the event this is called again
91-
}
89+
Set(key, value);
90+
}, key); // use property name(key) as subscriptionId to prevent excess subscription creation in the event this is called again
9291
}
9392
}
9493

tests/abstractions/Store/InMemoryBackingStoreTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,15 @@ public void TestsLargeArrayPerformsWell()
475475
var testBackingStore = new InMemoryBackingStore();
476476
// Act
477477
Assert.Empty(testBackingStore.Enumerate());
478-
testBackingStore.Set("email", _testArray);
479478
var stopWatch = Stopwatch.StartNew();
479+
testBackingStore.Set("email", _testArray);
480+
stopWatch.Stop();
481+
Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 1);
482+
stopWatch.Restart();
480483
testBackingStore.InitializationCompleted = true;
481484
stopWatch.Stop();
482485
// Assert
483-
Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 2);
486+
Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 1);
484487
}
485488

486489
/// <summary>

0 commit comments

Comments
 (0)