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

perf: Optimize templates resource loading peformance #9090

Merged

Conversation

filzrev
Copy link
Contributor

@filzrev filzrev commented Aug 15, 2023

What's included in this PR
Small perf optimization related to templates resource loading.

  • Remove unnecessary CreateTemplateResource() call.
  • Call ToArray() before IResourceFileReader::Names property is set.
    Because Names are enumerated multiple times.
  • Add HashSet<string> for Names check. Because ResourceFileReader::GetResourceStream is called multiple times.
    For example. it is called about 443 times for samples/seed project.
    And Names contains 71/93 elements (For default/modern templates).

@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (bfefe72) 77.57% compared to head (50e9703) 77.58%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9090   +/-   ##
=======================================
  Coverage   77.57%   77.58%           
=======================================
  Files         592      592           
  Lines       24606    24608    +2     
=======================================
+ Hits        19088    19091    +3     
+ Misses       5518     5517    -1     
Files Changed Coverage Δ
src/Docfx.Build.Engine/DocumentBuilder.cs 79.53% <100.00%> (-0.12%) ⬇️
...ine/ResourceFileReaders/CompositeResourceReader.cs 88.88% <100.00%> (ø)
...ine/ResourceFileReaders/LocalFileResourceReader.cs 81.81% <100.00%> (+1.81%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@yufeih yufeih left a comment

Choose a reason for hiding this comment

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

Aha, improper use of LINQ easily cause perf problems.

@yufeih yufeih merged commit 706a10c into dotnet:main Aug 16, 2023
@filzrev filzrev deleted the perf-optimize-templates-resource-loading branch August 17, 2023 00:50
@yufeih yufeih added the new-feature Makes the pull request to appear in "New Features" section of the next release note label Aug 17, 2023
p-kostov pushed a commit to ErpNetDocs/docfx that referenced this pull request Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature Makes the pull request to appear in "New Features" section of the next release note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants