diff --git a/CHANGELOG.md b/CHANGELOG.md index 05440214..a762e133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Directory.Build.props b/Directory.Build.props index cd005950..60173a4a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.11.0 + 1.11.1 false diff --git a/src/abstractions/store/InMemoryBackingStore.cs b/src/abstractions/store/InMemoryBackingStore.cs index e5bd1f3a..8cf79553 100644 --- a/src/abstractions/store/InMemoryBackingStore.cs +++ b/src/abstractions/store/InMemoryBackingStore.cs @@ -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(innerItem.Key); - } + backedModel.BackingStore.Get(innerItem.Key); } } diff --git a/tests/abstractions/Store/InMemoryBackingStoreTests.cs b/tests/abstractions/Store/InMemoryBackingStoreTests.cs index 85ff67c6..599b30fd 100644 --- a/tests/abstractions/Store/InMemoryBackingStoreTests.cs +++ b/tests/abstractions/Store/InMemoryBackingStoreTests.cs @@ -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; @@ -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); + } /// /// Helper function to pull out the private `subscriptions` collection property from the InMemoryBackingStore class