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

NativeAOT SetCreateObject on JsonTypeInfo<T> could be slimmed down #83608

Closed
NinoFloris opened this issue Mar 17, 2023 · 7 comments
Closed

NativeAOT SetCreateObject on JsonTypeInfo<T> could be slimmed down #83608

NinoFloris opened this issue Mar 17, 2023 · 7 comments
Labels
area-System.Text.Json linkable-framework Issues associated with delivering a linker friendly framework needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity
Milestone

Comments

@NinoFloris
Copy link
Contributor

NinoFloris commented Mar 17, 2023

SetCreateObject on JsonTypeInfo<T> currently holds code to deal with the untyped/typed delegate and validation. This bloats every instantiation of JsonTypeInfo<T> while it should just do the bare minimum for the typed side to work.

It seems trivial to move the validation and untyped setter logic into a new non virtual method on JsonTypeInfo, this would then call into the abstract SetCreateObject to just do the last bits for the typed delegate in JsonTypeInfo<T>.

For specifically this path SetCreateObject would probably need to be changed to return its typed delegate as Func<object> (or Func (or null if it's not applicable) though it could also just overwrite _createObject.

else if (createObject is Func<T> typedDelegate)
{
typedCreateObject = typedDelegate;
untypedCreateObject = createObject is Func<object> untypedDelegate ? untypedDelegate : () => typedDelegate()!;
}

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 17, 2023
@ghost
Copy link

ghost commented Mar 17, 2023

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

SetCreateObject on JsonTypeInfo<T> currently holds code to deal with the untyped/typed delegate and validation. This bloats every instantiation of JsonTypeInfo<T> while it should just do the bare minimum for the typed side to work.

It seems trivial to move the validation and untyped setter logic into a new non virtual method on JsonTypeInfo, this would then call into the abstract SetCreateObject to just do the last bits for the typed delegate in JsonTypeInfo<T>.

For specifically this path SetCreateObject would probably need to be changed to return its typed delegate (or null if it's not applicable) though it could also just overwrite _createObject.

else if (createObject is Func<T> typedDelegate)
{
typedCreateObject = typedDelegate;
untypedCreateObject = createObject is Func<object> untypedDelegate ? untypedDelegate : () => typedDelegate()!;
}

Author: NinoFloris
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@eiriktsarpalis
Copy link
Member

It might help if you could share a PR that demonstrates the change. Thanks.

@krwq krwq added the linkable-framework Issues associated with delivering a linker friendly framework label Mar 18, 2023
@ghost
Copy link

ghost commented Mar 18, 2023

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr
See info in area-owners.md if you want to be subscribed.

Issue Details

SetCreateObject on JsonTypeInfo<T> currently holds code to deal with the untyped/typed delegate and validation. This bloats every instantiation of JsonTypeInfo<T> while it should just do the bare minimum for the typed side to work.

It seems trivial to move the validation and untyped setter logic into a new non virtual method on JsonTypeInfo, this would then call into the abstract SetCreateObject to just do the last bits for the typed delegate in JsonTypeInfo<T>.

For specifically this path SetCreateObject would probably need to be changed to return its typed delegate as Func<object> (or Func (or null if it's not applicable) though it could also just overwrite _createObject.

else if (createObject is Func<T> typedDelegate)
{
typedCreateObject = typedDelegate;
untypedCreateObject = createObject is Func<object> untypedDelegate ? untypedDelegate : () => typedDelegate()!;
}

Author: NinoFloris
Assignees: -
Labels:

area-System.Text.Json, untriaged, linkable-framework

Milestone: -

@krwq krwq added this to the 8.0.0 milestone Mar 18, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 18, 2023
@krwq
Copy link
Member

krwq commented Mar 18, 2023

@NinoFloris please provide sample and potential saving (can be in terms of number of method i.e. or if you have numbers from mstat file - you can get mstat file using these instructions: #78671 (comment) and dump it using https://gist.github.com/eerhardt/9c56e6c60952adf8b463839e7670c7ce) then you can search for methods you think can be removed. Also make sure to show the sample app you run this on and show potential size saving in perspective of total.

I'm marking this as potential 8.0.

@eiriktsarpalis eiriktsarpalis modified the milestones: 8.0.0, Future May 31, 2023
@eiriktsarpalis eiriktsarpalis added the needs-author-action An issue or pull request that requires more info or actions from the author. label May 31, 2023
@ghost
Copy link

ghost commented May 31, 2023

This issue has been marked needs-author-action and may be missing some important information.

@ghost ghost added the no-recent-activity label Jun 14, 2023
@ghost
Copy link

ghost commented Jun 14, 2023

This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@ghost
Copy link

ghost commented Jun 29, 2023

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@ghost ghost closed this as completed Jun 29, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 29, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json linkable-framework Issues associated with delivering a linker friendly framework needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity
Projects
None yet
Development

No branches or pull requests

3 participants