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

Use Type.GetProperty/GetField instead of GetMember. #103275

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

eiriktsarpalis
Copy link
Member

Following up from the discussion of dotnet/aspnetcore#56139. This PR replaces Type.GetMember for MemberInfo resolution with Type.GetField/GetProperty.

@MichalStrehovsky
Copy link
Member

rt-sz doesn't report any improvement from this (MichalStrehovsky/rt-sz#30), but also it doesn't test with the TodosApi app so I don't know if it would help there. rt-sz saw a small regression with the PR that added this: MichalStrehovsky/rt-sz#28 but the regression was much smaller than what we saw with todosapi so I don't know :/

@MichalStrehovsky
Copy link
Member

rt-sz doesn't report any improvement from this (MichalStrehovsky/rt-sz#30), but also it doesn't test with the TodosApi app so I don't know if it would help there. rt-sz saw a small regression with the PR that added this: MichalStrehovsky/rt-sz#28 but the regression was much smaller than what we saw with todosapi so I don't know :/

Ah, rt-sz wouldn't really capture improvements in changes like this. It doesn't pick up the new source generator. So a zero diff result is expected. We don't have a good way to measure impact of this in automation.

@eiriktsarpalis
Copy link
Member Author

I wouldn't expect it to create a lot of impact size-wise. The main issue I would think is finding a good way to make the AttributeProviderFactory delegate trimmable if it isn't being invoked. Any suggestions?

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Jun 11, 2024

I wouldn't expect it to create a lot of impact size-wise. The main issue I would think is finding a good way to make the AttributeProviderFactory delegate trimmable if it isn't being invoked. Any suggestions?

Is the public surface are immutable (i.e. we cannot unseal JsonPropertyInfoValues<T> and change how AttributeProviderFactory property is implemented by making it virtual or something like that)?

@eiriktsarpalis
Copy link
Member Author

You mean have the source generator override a virtual method? Would that make it more amenable to trimming?

@MichalStrehovsky
Copy link
Member

We're quite a bit limited that the typeof(Foo).GetProperty("Bar") needs to use literals everywhere because trimming needs to see this sequence. At this point I'm mostly thinking whether we can at least get rid of all the lambdas with something like:

class Provider
{
    private PropertyInfo _pi;
    public Provider(PropertyInfo pi) =>_pi = pi;
    public ICustomAttributeProvider Get() => _pi;
}

then do AttributeProviderFactory = new Provider(typeof(Foo).GetProperty("Bar")).Get;

Or even make a custom JsonPropertyInfoValues<T> descendant that overrides AttributeProviderFactory with this impl. I don't know if there's a chance to trim the typeof(Foo).GetProperty("Bar") part. At least I don't quickly see anything.

@eiriktsarpalis
Copy link
Member Author

The lambda is there so that attribute provider resolution can be done lazily. By making it eager we'd end up penalizing startup in all uses of the source generator.

@eiriktsarpalis
Copy link
Member Author

@MichalStrehovsky I'm thinking we should merge this change regardless, given that it has first-class support from the linker.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

This is an improvement from trimming perspective because we no longer root all members on the type (GetMembers is not intrinsically recognized by trimming and will root all members on the typeof). GetProperty/GetField will only root that single field/property.

@eiriktsarpalis
Copy link
Member Author

/ba-g unrelated infra failure

@github-actions github-actions bot locked and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants