Repository navigation
Optimize ResourceContainer/AssemblyLoadEventHandler methods, remove allocs - #9822
Merged
Merged
Conversation
dotnet-policy-service
Bot
requested review from
dipeshmsft and
singhashish-wpf
September 20, 2024 09:29
edwardneal
reviewed
Sep 23, 2024
edwardneal
left a comment
Contributor
There was a problem hiding this comment.
Looking good! Does the benchmark handle the startup of an app with something bound to an embedded image resource? There's a call to Assembly.Load in the call stack of ResourceContainer.GetPart (GetPart -> GetPartCore -> GetResourceManagerWrapper -> BaseUriHelper.GetLoadedAssembly -> Assembly.Load) and it feels like this is going to be the largest performance killer in the worst-case scenario; I'm curious to see whether it's triggered under normal circumstances.
miloush
reviewed
Sep 23, 2024
miloush
reviewed
Sep 23, 2024
Member
|
@adamsitnik wanted to point this out to you as it is doing some assembly name parsing in a hot path for WPF. |
h3xds1nz
force-pushed
the
resourcecontainer-allocs
branch
from
January 22, 2025 09:47
e553fa0 to
0d1084d
Compare
h3xds1nz
added a commit
to h3xds1nz/wpf
that referenced
this pull request
Jan 23, 2025
himgoyalmicro
approved these changes
Feb 3, 2025
Contributor
|
Thank you @h3xds1nz for your continuous contributions 😄 |
Member
Author
|
@himgoyalmicro Thank you, happy this one is in <3 |
h3xds1nz
added a commit
to h3xds1nz/wpf
that referenced
this pull request
Feb 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Optimizes two rather important startup methods in
ResourceContainerclass, the handler for runtime assembly load events -OnAssemblyLoadEventHandlerandGetResourceManagerWrapper. This saves several milliseconds upon startup.StringComparer.OrdinalIgnoreCaseas it would be slower by ~60ns in the final solution.RuntimeAssembly), I've re-used the Optimize retrieval of simple name from Assembly.FullName, fix up faulty methods #9739 and added a new method forVersion/PublicKeyTokenArrayPool<char>for the unlikely event of needing an array (256+ chars) but seems redundant to initialize it this early, and we shall not really need to allocate an array anyways in 99% cases.AlternativeLookup, this now becomes fully allocation-free given that usually only 1 entry is in the dictionary.ToLowerInvariantproduces same-length output, the own function's sanity check and several other dotnet runtime libraries (plus tons of user code) depend on this behavior of per-character folding.Do note that these benchmarks measure throughput and allocations (accurate), the savings are in milliseconds this early.
Allocations are dependent on presence of public key / assembly name length, this just illustrates general scenario.
Single throughput of AssemblyLoadHandler
Standard app startup (28 libraries loaded)
Customer Impact
Improved startup performance, decreased startup allocations.
Regression
No.
Testing
Local build, running few sample apps using resources and verifying functionality.
Risk
Low, I believe I didn't achieve any change of the behavior, even unintentionally.
Microsoft Reviewers: Open in CodeFlow