Skip to content

Fix delegate allocation in CachingContext.GetOrAddJsonTypeInfo #80437

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

Merged
merged 3 commits into from
Jan 11, 2023

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Jan 10, 2023

Fixes #80430
Allocation regression from #71746

@ghost
Copy link

ghost commented Jan 10, 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

Fixes #80430

Author: stephentoub
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@@ -156,11 +156,14 @@ internal void ClearCaches()
internal sealed class CachingContext
{
private readonly ConcurrentDictionary<Type, JsonTypeInfo?> _jsonTypeInfoCache = new();
private readonly Func<Type, JsonTypeInfo?> _jsonTypeInfoFactory;
Copy link
Member

Choose a reason for hiding this comment

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

consider adding comment why we're doing this (it's one of the things I'd personally by default choose shorter code)

@stephentoub stephentoub merged commit 4881062 into dotnet:main Jan 11, 2023
@stephentoub stephentoub deleted the jsonalloc branch January 11, 2023 13:18
@cmeeren
Copy link

cmeeren commented Jan 11, 2023

Thanks! Know when this will be released? (Just so I know when to watch out for it)

@eiriktsarpalis
Copy link
Member

Thanks! Know when this will be released? (Just so I know when to watch out for it)

It should be available in the first preview release of .NET 8.

@stephentoub @ericstj do you think this meets the bar for servicing? The issue would impact performance in applications that make heavy use of polymorphism.

@eiriktsarpalis
Copy link
Member

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3895615065

@github-actions
Copy link
Contributor

@eiriktsarpalis backporting to release/7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix delegate allocation in CachingContext.GetOrAddJsonTypeInfo
Applying: Address PR feedback
error: sha1 information is lacking or useless (src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Caching.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Address PR feedback
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@eiriktsarpalis an error occurred while backporting to release/7.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

eiriktsarpalis pushed a commit to eiriktsarpalis/runtime that referenced this pull request Jan 11, 2023
…t#80437)

* Fix delegate allocation in CachingContext.GetOrAddJsonTypeInfo

* Address PR feedback
carlossanlop pushed a commit that referenced this pull request Jan 12, 2023
…ypeInfo (#80513)

* Fix delegate allocation in CachingContext.GetOrAddJsonTypeInfo (#80437)

* Fix delegate allocation in CachingContext.GetOrAddJsonTypeInfo

* Address PR feedback

* Ensure CachingContext.Options isn't being trimmed away.

* Update servicing version

Co-authored-by: Stephen Toub <[email protected]>
@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Jan 31, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 2, 2023
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.

Massive allocations of Func<Type, JsonTypeInfo> in System.Text.Json.JsonSerializerOptions+CachingContext.GetOrAddJsonTypeInfo(Type)
4 participants