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

Reduce ExtensionManager memory allocations #12588

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

lahma
Copy link
Contributor

@lahma lahma commented Oct 8, 2022

TLDR; reduce test suite memory allocations by 40GB (> 90%).

I profiled tests run by OrchardCode suite to check if there's any easy wins to make them go faster. I was quite surprised by the memory allocation for the whole suite when run in Release mode, it was almost 44GB of memory allocated during the suite run.

After analysis I found out the ExtensionManager to be the culprit. It has a lot of closures and allocatey-LINQ usage + enumerators from interface use. Generally, I'd say it would be fine if done once but as it's repeated every time when system initializes in tests, it starts to cost.

I went through the code and made it less cool by using concrete types, more imperative constructs instead of LINQ and better equality lookups (feature id instead of feature object).

The test suite now allocates 40GB less during run and the ExtensionManager should be the same functionality-wise. This helps with the test suite performance and probably also with OrchardCore cold startup speed at least.

Relates to #12583

Before

image

After

image

@lahma
Copy link
Contributor Author

lahma commented Oct 8, 2022

Comparing to other PR "Deprecate ILuceneSearchQueryService in OrchardCore.Search.Lucene" which was run 11 hours ago and its run times, of course very unscientific because might have been different runner etc.

Other PR

image

Run dotnet test -c Release --no-restore --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
Test run for /home/runner/work/OrchardCore/OrchardCore/test/OrchardCore.Tests/bin/Release/net6.0/OrchardCore.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.3.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {16ab46fb-abaa-44d6-[8](https://github.com/OrchardCMS/OrchardCore/actions/runs/3207591444/jobs/5242632583#step:6:9)e[9](https://github.com/OrchardCMS/OrchardCore/actions/runs/3207591444/jobs/5242632583#step:6:10)b-83480[12](https://github.com/OrchardCMS/OrchardCore/actions/runs/3207591444/jobs/5242632583#step:6:13)47b5e} may be persisted to storage in unencrypted form.

Passed!  - Failed:     0, Passed:   964, Skipped:     0, Total:   964, Duration: 1 m 7 s - /home/runner/work/OrchardCore/OrchardCore/test/OrchardCore.Tests/bin/Release/net6.0/OrchardCore.Tests.dll (net6.0)

This PR

image

Run dotnet test -c Release --no-restore --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
Test run for /home/runner/work/OrchardCore/OrchardCore/test/OrchardCore.Tests/bin/Release/net6.0/OrchardCore.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.3.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {66fa1553-3[8](https://github.com/OrchardCMS/OrchardCore/actions/runs/3209629134/jobs/5246493936#step:6:9)b1-4f47-a4d6-[9](https://github.com/OrchardCMS/OrchardCore/actions/runs/3209629134/jobs/5246493936#step:6:10)9d4d[10](https://github.com/OrchardCMS/OrchardCore/actions/runs/3209629134/jobs/5246493936#step:6:11)d495c} may be persisted to storage in unencrypted form.

Passed!  - Failed:     0, Passed:   964, Skipped:     0, Total:   964, Duration: 24 s - /home/runner/work/OrchardCore/OrchardCore/test/OrchardCore.Tests/bin/Release/net6.0/OrchardCore.Tests.dll (net6.0)

@sebastienros sebastienros merged commit c2a6a26 into OrchardCMS:main Oct 13, 2022
@lahma lahma deleted the optimize-extension-manager branch October 13, 2022 19:51
@lahma
Copy link
Contributor Author

lahma commented Oct 14, 2022

Could I get hacktoberfest-accepted label for this PR as a reward, it seems to be available in the repo 🙏🏻

@Piedone
Copy link
Member

Piedone commented Oct 19, 2022

Awesome!

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

Successfully merging this pull request may close these issues.

4 participants