Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

[release/3.1] Port cache polymorphic properties (#41753)#42057

Merged
steveharter merged 1 commit into
dotnet:release/3.1from
steveharter:PortPolymorphicPerf
Oct 23, 2019
Merged

[release/3.1] Port cache polymorphic properties (#41753)#42057
steveharter merged 1 commit into
dotnet:release/3.1from
steveharter:PortPolymorphicPerf

Conversation

@steveharter

@steveharter steveharter commented Oct 23, 2019

Copy link
Copy Markdown
Contributor

note: this PR was created and made stand-alone since the previous PR that included this fix takes a dependency on collection PR that will likely not be accepted.

Ports #41753

Issue

With the PR there is significant performance improvement when using polymorphic serialization. The issue was created and fixed by a community member by adding a dictionary-based cache and reports real-world gains of 68x.

Description

When a property of type of System.Object is serialized, the serializer enters a polymorphic mode where it obtains the actual run-time type to serialize. Getting the appropriate infrastructure (including looking up a converter for that type and generating IL for the setter) is expensive and was not cached. This PR caches that information.

Customer Impact

  • Slow behavior when using polymorphic serialization.

Regression?

No.

Risk

Low.
The performance issue is very specific to polymorphic serialization which was already tested. An additional test was added to verify the cache is properly keying.

* Cache polymorphic properties

* Move RuntimePropertyCache to JsonClassInfo

* Added test of RuntimePropertyCache using properties with different attributes

* Fixed typo

Co-Authored-By: Ahson Khan <ahkha@microsoft.com>

* Use allocating overload of GetOrAdd on .Net Standard 2.0
@steveharter steveharter added the tenet-performance Performance related issue label Oct 23, 2019
@danmoseley danmoseley added the api-approved API was approved in API review, it can be implemented label Oct 23, 2019
@danmoseley

Copy link
Copy Markdown
Member

Approved. Customer reported performance concern, substantial impact, relatively localized change. Please merge by 4pm.

@danmoseley danmoseley added Servicing-approved Approved for servicing release and removed api-approved API was approved in API review, it can be implemented labels Oct 23, 2019
@steveharter steveharter merged commit 3d73b19 into dotnet:release/3.1 Oct 23, 2019
@steveharter steveharter deleted the PortPolymorphicPerf branch October 23, 2019 21:01
@ahsonkhan

Copy link
Copy Markdown

Fixes https://github.com/dotnet/corefx/issues/41638 for release/3.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.Json Servicing-approved Approved for servicing release tenet-performance Performance related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants