Skip to content

Commit

Permalink
Merge pull request #326 from microsoft/bugfix/backing-store-perf
Browse files Browse the repository at this point in the history
fix: performance issue with the backing store
  • Loading branch information
baywet authored Aug 13, 2024
2 parents 65257cb + b318b46 commit 7b1d978
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 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.1] - 2024-08-12

### Changed

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

## [1.11.0] - 2024-08-08

- Enabled Continuous Access evaluation by default.
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.0</VersionPrefix>
<VersionPrefix>1.11.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- This is overidden in test projects by setting to true-->
<IsTestProject>false</IsTestProject>
Expand Down
10 changes: 5 additions & 5 deletions src/abstractions/store/InMemoryBackingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ private void EnsureCollectionPropertyIsConsistent(string key, object? storeItem)
// Call Get<>() on nested properties so that this method may be called recursively to ensure collections are consistent
foreach(var item in collectionTuple.Item1)
{
if(item is IBackedModel backedModel)
if(item is not IBackedModel backedModel) break;
// there are no mixed collections if the first element is not a IBackedModel, not need to iterate over the collection

foreach(var innerItem in backedModel.BackingStore.Enumerate())
{
foreach(var innerItem in backedModel.BackingStore.Enumerate())
{
backedModel.BackingStore.Get<object>(innerItem.Key);
}
backedModel.BackingStore.Get<object>(innerItem.Key);
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/abstractions/Store/InMemoryBackingStoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Microsoft.Kiota.Abstractions.Store;
Expand Down Expand Up @@ -466,6 +467,21 @@ public void TestsBackingStoreNestedInvocationCounts()

Assert.Equal(2, invocationCount);// only called twice
}
private readonly int[] _testArray = Enumerable.Range(0, 100000000).ToArray();
[Fact]
public void TestsLargeArrayPerformsWell()
{
// Arrange
var testBackingStore = new InMemoryBackingStore();
// Act
Assert.Empty(testBackingStore.Enumerate());
testBackingStore.Set("email", _testArray);
var stopWatch = Stopwatch.StartNew();
testBackingStore.InitializationCompleted = true;
stopWatch.Stop();
// Assert
Assert.InRange(stopWatch.ElapsedMilliseconds, 0, 2);
}

/// <summary>
/// Helper function to pull out the private `subscriptions` collection property from the InMemoryBackingStore class
Expand Down

0 comments on commit 7b1d978

Please sign in to comment.