-
Notifications
You must be signed in to change notification settings - Fork 494
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
Serialization / CosmosElements: Adds LazyCosmosElement Cache Improvements #1943
Serialization / CosmosElements: Adds LazyCosmosElement Cache Improvements #1943
Conversation
...ure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/ChangeFeedEstimatorIteratorTests.cs
Outdated
Show resolved
Hide resolved
Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/Aggregate/Aggregators/SingleGroupAggregator.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the caching implementation is about what I would expect. A few concerns about defining specific implementations on the public surface area for CosmosArray/CosmosObject, as it establishes a precedent that may be detrimental to us going forward.
Closing due to in-activity, pease feel free to re-open. |
Serialization / CosmosElements: Adds LazyCosmosElement Cache Improvements
Description
Improves the cache for LazyCosmosElements. After adding a benchmark LazyCosmosElements it was evident that the cacheing story was not exhaustive. Enumerating would always reparse the buffer for the JsonElement instead of serving from the cache. The new design is just initializing LazyCosmosElements for every element in the array or object. This is fine since the elements are lazy and cheap to create (by the recursive nature of lazy JSON). This all of nothing approach leads to less state management, which turns out to be more performant then the previous conservative approach.
Also for Array and Object enumerators we return a struct now instead of interface to avoid boxing. This makes the enumeration code paths allocation free.
Benchmarks:
Before:
After:
For arrays we are looking at about 33% less memory utilization for the once and many scenario
For objects we are looking at 1/4th the memory for never, 1/100th for once, and 1/400th for many.
Unit tests were also added to cover these optimizations.