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

Improve ShapeTableManager performance #15620

Merged
merged 4 commits into from
Apr 1, 2024
Merged

Improve ShapeTableManager performance #15620

merged 4 commits into from
Apr 1, 2024

Conversation

sebastienros
Copy link
Member

No description provided.

{
var strategyFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType());
var hostingEnvironment = _serviceProvider.GetRequiredService<IHostEnvironment>();
var bindingStrategies = _serviceProvider.GetRequiredService<IEnumerable<IShapeTableProvider>>();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one specifically creates a list of IShapeTableProvider which themselves have other collections resolved. And this was done multiple times per request since it was transient. Now the collections are materialized (with resolved elements) only when the shape is actually built.


HashSet<string> excludedFeatures;
return BuildShapeTableAsync(themeId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting the async path allows dotnet to optimize the call for the most common case which is when we read the shape table from cache.

private readonly ITypeFeatureProvider _typeFeatureProvider;
private readonly IMemoryCache _memoryCache;
// Singleton cache to hold a tenant's theme ShapeTable
private readonly Dictionary<string, ShapeTable> _shapeTableCache;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a singleton dictionary as the cache, like IMemoryCache, with the difference that it is indexed by something we don't need to make unique with a prefix since it is only used here.
The dependency is keyed just in case some other component might want to also register the same type.

Copy link
Member

@MikeAlhayek MikeAlhayek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -1,3 +1,4 @@
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this has been added accidentally?!!

return _extensionManager
.GetFeatureDependencies(themeId)
.Any(f => f.Id == themeFeatureId);
bool IsBaseTheme(string themeFeatureId, string themeId)
Copy link
Member

@hishamco hishamco Mar 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's right to use it as a local function, but no problem while you make IsModuleOrRequestedTheme static

))
.ToList();
var enabledAndOrderedFeatureIds = (await shellFeaturesManager.GetEnabledFeaturesAsync())
.Select(f => f.Id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.Select(f => f.Id)
.OrderBy(f => f.Id)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the previous code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how these Ids are ordered without OrderBy?

…peTableManagerTests.cs

Co-authored-by: Hisham Bin Ateya <[email protected]>
@sebastienros sebastienros enabled auto-merge (squash) April 1, 2024 16:48
@sebastienros sebastienros merged commit 0fbcf21 into main Apr 1, 2024
5 checks passed
@sebastienros sebastienros deleted the sebros/shapetable branch April 1, 2024 16:55
@hyzx86
Copy link
Contributor

hyzx86 commented Apr 10, 2024

Hi @sebastienros ,Is this issue realted to this PR #15715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants