Skip to content

Commit

Permalink
Merge pull request #328 from microsoft/bugfix/backing-store-perf
Browse files Browse the repository at this point in the history
fix: performance issue with InMemoryBackingStore
  • Loading branch information
baywet authored Aug 14, 2024
2 parents b924784 + b5f3635 commit e81e178
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.11.2] - 2024-08-14

### Changed

- Fixed an additional performance regression with the backing store introduced in version 1.9.2 by #243

## [1.11.1] - 2024-08-12

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- Common default project properties for ALL projects-->
<PropertyGroup>
<VersionPrefix>1.11.1</VersionPrefix>
<VersionPrefix>1.11.2</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- This is overidden in test projects by setting to true-->
<IsTestProject>false</IsTestProject>
Expand Down
13 changes: 6 additions & 7 deletions src/abstractions/store/InMemoryBackingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ public void Set<T>(string key, T? value)
// All the list items are dirty as the model has been touched.
foreach(var item in collectionValues)
{
if(item is IBackedModel model)
// we don't support heterogeneous collections, so we can break if the first item is not a IBackedModel
if(item is not IBackedModel model) break;
model.BackingStore.InitializationCompleted = false;
model.BackingStore.Subscribe((keyString, oldObject, newObject) =>
{
model.BackingStore.InitializationCompleted = false;
model.BackingStore.Subscribe((keyString, oldObject, newObject) =>
{
Set(key, value);
}, key); // use property name(key) as subscriptionId to prevent excess subscription creation in the event this is called again
}
Set(key, value);
}, key); // use property name(key) as subscriptionId to prevent excess subscription creation in the event this is called again
}
}

Expand Down
7 changes: 5 additions & 2 deletions tests/abstractions/Store/InMemoryBackingStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,15 @@ public void TestsLargeArrayPerformsWell()
var testBackingStore = new InMemoryBackingStore();
// Act
Assert.Empty(testBackingStore.Enumerate());
testBackingStore.Set("email", _testArray);
var stopWatch = Stopwatch.StartNew();
testBackingStore.Set("email", _testArray);
stopWatch.Stop();
Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 1);
stopWatch.Restart();
testBackingStore.InitializationCompleted = true;
stopWatch.Stop();
// Assert
Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 2);
Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 1);
}

/// <summary>
Expand Down

0 comments on commit e81e178

Please sign in to comment.