Skip to content
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

fix: performance issue with InMemoryBackingStore #328

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading