Skip to content

Generated the AssemblyRecord code in AssemblyHelper to improve startup performance - #7033

Merged
dipeshmsft merged 1 commit into
dotnet:mainfrom
dotnet-campus:t/lindexi/AssemblyRecordInAssemblyHelper
Mar 20, 2023
Merged

dipeshmsft merged 1 commit into
dotnet:mainfrom
dotnet-campus:t/lindexi/AssemblyRecordInAssemblyHelper

Conversation

@lindexi

@lindexi lindexi commented Sep 13, 2022 •

Copy link
Copy Markdown
Member

Description

The AssemblyHelper will create the AssemblyRecord[] by UncommonAssembly. And the code will be run when the application startup.

And I think it's worth doing this optimization to improve startup performance. And I don't think these Uncommon Assembly will be added or changed.

Benchmark result:

BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19044.1645/21H2/November2021Update)
Intel Core i7-6700 CPU 3.40GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.400
  [Host]     : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2
  DefaultJob : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2

Method Mean Error StdDev Ratio
OriginalCode 281.07 ns 4.154 ns 3.469 ns 1.00
OptimizedCode1 36.25 ns 0.703 ns 1.030 ns 0.13
OptimizedCode2 18.35 ns 0.449 ns 0.584 ns 0.07

Benchmark code: https://github.com/lindexi/lindexi_gd/blob/7d0d7d5a5bbd12b67480413a17bc43197454b54a/KairfeefaqaiJeaqenuna/KairfeefaqaiJeaqenuna/Program.cs

Customer Impact

Slightly slow startup performance issues.

Regression

None.

Testing

Just CI and the benchmark code.

Risk

Very low. The code is changed equivalently. No behavior was changed.

Microsoft Reviewers: Open in CodeFlow

@lindexi
lindexi requested a review from a team as a code owner September 13, 2022 07:13
@ghost ghost assigned lindexi Sep 13, 2022
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Sep 13, 2022
@ghost
ghost requested review from SamBent, dipeshmsft and singhashish-wpf September 13, 2022 07:13
@ghost ghost added the Community Contribution A label for all community Contributions label Sep 13, 2022
lindexi added a commit to lindexi/lindexi_gd that referenced this pull request Sep 13, 2022
@dipeshmsft

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@dipeshmsft dipeshmsft self-assigned this Feb 2, 2023
@dipeshmsft

Copy link
Copy Markdown
Member

@lindexi, this PR looks good, but our only concern with this PR is that hard-coding the list will make the maintenance harder. Thoughts?

@lindexi

lindexi commented Feb 13, 2023

Copy link
Copy Markdown
Member Author

Thank you @dipeshmsft

I agree with you. But I don't think it's possible to add new assemblies. In other words, this is the constant.

@dipeshmsft

Copy link
Copy Markdown
Member

Thanks @lindexi for your contributions in performance.

@miloush

miloush commented Mar 24, 2023

Copy link
Copy Markdown
Contributor

And I don't think these Uncommon Assembly will be added or changed.

Why do you think so? They have been changed in the past, cf. https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/AssemblyHelper.cs,d11803a9eea58251

@lindexi

lindexi commented Mar 27, 2023

Copy link
Copy Markdown
Member Author

@miloush What is cf means?

@miloush

miloush commented Mar 27, 2023

Copy link
Copy Markdown
Contributor

@lindexi "confer", means compare - as in the list of assemblies is now different than it was in .NET Framework.

@lindexi

lindexi commented Mar 28, 2023

Copy link
Copy Markdown
Member Author

@miloush Thank you. You are right. Can I ask you for advice?

@miloush

miloush commented Apr 1, 2023 •

Copy link
Copy Markdown
Contributor

Well the fact that they are both in the same file helps a bit with the maintenance. I would have put a comment on the enum that the static AssemblyHelper constructor needs to be updated when changes are done to the enum or vice versa.

Also why didn't you just do

_records = new AssemblyRecord[5];
_records[0].Name = "System.Drawing.Common,";
_records[1].Name = "System.Private.Xml,";
...

However since this is merged now, I guess you can leave it be.

@ghost ghost locked as resolved and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants