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

Improve MauiFactory performance by avoiding reflection to get base classes #24775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

albyrock87
Copy link
Contributor

@albyrock87 albyrock87 commented Sep 15, 2024

Description of Change

A minor improvement to a piece of code executed on every ToHandler or ToPlatform.

Speedscope Before
image

Speedscope After
image

Extra note
I had some code ready to cache the entire Type => ServiceDescriptor(s) and make this even faster, but it breaks a unit test which honestly I don't understand the purpose of:

public void CanChangeHandlerRegistration()
{
var mauiApp = MauiApp.CreateBuilder()
.ConfigureMauiHandlers(handlers => handlers.AddHandler<ButtonStub, ButtonHandlerStub>())
.Build();
var specificHandler = mauiApp.Services.GetRequiredService<IMauiHandlersFactory>().GetHandler(typeof(ButtonStub));
Assert.IsType<ButtonHandlerStub>(specificHandler);
mauiApp.Services.GetRequiredService<IMauiHandlersFactory>().GetCollection().AddHandler<ButtonStub, AlternateButtonHandlerStub>();
var alternateHandler = mauiApp.Services.GetRequiredService<IMauiHandlersFactory>().GetHandler(typeof(ButtonStub));
Assert.IsType<AlternateButtonHandlerStub>(alternateHandler);
}

@albyrock87 albyrock87 requested a review from a team as a code owner September 15, 2024 11:50
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 15, 2024
@tj-devel709 tj-devel709 added the area-core-hosting Extensions / Hosting / AppBuilder / Startup label Sep 16, 2024
@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen requested review from jonathanpeppers and removed request for jfversluis September 17, 2024 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup community ✨ Community Contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants