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

AssemblyScanner improvements #6814

Merged
merged 20 commits into from
Aug 31, 2023
Merged

AssemblyScanner improvements #6814

merged 20 commits into from
Aug 31, 2023

Conversation

danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented Aug 24, 2023

Improves the assembly scanner performance in "regular cases" slightly and in cases when the exclusion list is larger, up to 4 times.

I was doing some investigations for a customer that mentioned they are seeing slow startup times in their rather large solution. Once I was able to get my hands on the profiler data it was apparent that the IsExcluded check is the culprit.

Scenarios

I have created a solution generator that allows simulating arbitrary solution sizes. As a reference point, I created a solution with roughly 960 projects and more than 140K types.

Without Exclusions

Before

image

After

image

With a larger number of exclusions

Before

image

Here is the excerpt from the customer callstack

image

After

image

Benchmarks

Attribute.GetCustomAttribute

Method Mean Error StdDev Median Ratio RatioSD
Type 1,148.2 ns 135.51 ns 386.63 ns 1,010.9 ns 1.00 0.00
AttributeBased 804.7 ns 12.05 ns 11.27 ns 801.7 ns 0.99 0.20

Matching Strings

Method Input Mean Error StdDev Ratio Gen 0 Allocated
MatchOriginal SomeAssembly 146.94 ns 0.815 ns 0.680 ns 1.00 0.0010 96 B
MatchOptimized SomeAssembly 28.90 ns 0.441 ns 0.368 ns 0.20 - -
MatchOptimizedHashSet SomeAssembly 17.72 ns 0.057 ns 0.047 ns 0.12 - -
MatchOriginal SomeAssembly.Dll 149.63 ns 2.527 ns 2.363 ns 1.00 0.0024 208 B
MatchOptimized SomeAssembly.Dll 59.56 ns 0.504 ns 0.447 ns 0.40 0.0011 96 B
MatchOptimizedHashSet SomeAssembly.Dll 11.01 ns 0.106 ns 0.089 ns 0.07 - -
MatchOriginal SomeAssembly.Exe 184.95 ns 1.662 ns 1.473 ns 1.00 0.0024 208 B
MatchOptimized SomeAssembly.Exe 72.69 ns 0.963 ns 0.901 ns 0.39 0.0011 96 B
MatchOptimizedHashSet SomeAssembly.Exe 10.87 ns 0.038 ns 0.036 ns 0.06 - -

PublicKeyValidation

Method Mean Error StdDev Ratio Gen 0 Allocated
Before 1,157.2 ns 13.39 ns 12.53 ns 1.00 0.0687 432 B
After 842.8 ns 7.07 ns 5.90 ns 0.73 0.0277 176 B

@danielmarbach danielmarbach changed the title Minor AssemblyScanner improvements AssemblyScanner improvements Aug 24, 2023
@danielmarbach danielmarbach marked this pull request as ready for review August 25, 2023 15:40
@danielmarbach
Copy link
Contributor Author

Once the PR is reviewed, I would want to patch 92da68a on current supported versions

Copy link
Contributor

@timbussmann timbussmann left a comment

Choose a reason for hiding this comment

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

some minor suggestions

@danielmarbach
Copy link
Contributor Author

@timbussmann I think I addressed all the comments

@danielmarbach danielmarbach force-pushed the assemblyscanner branch 3 times, most recently from 1074c5e to b086c29 Compare August 30, 2023 16:18
Copy link
Member

@bording bording left a comment

Choose a reason for hiding this comment

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

Left a comment about a comment (hah!) and pushed up a few minor tweaks.

This is a massive improvement!

src/NServiceBus.Core/Hosting/Helpers/AssemblyScanner.cs Outdated Show resolved Hide resolved
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.

AssemblyScanning exclusion list slows down the endpoint startup
3 participants