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

Remove Type caches in DataContractSerialization #42861

Open
eerhardt opened this issue Sep 29, 2020 · 1 comment
Open

Remove Type caches in DataContractSerialization #42861

eerhardt opened this issue Sep 29, 2020 · 1 comment
Labels
area-Serialization Priority:3 Work that is nice to have
Milestone

Comments

@eerhardt
Copy link
Member

In DataContractSerialization we have a few places where we are caching typeof(XX) into static Type variables. For example:

private static Type? s_typeOfObject;
internal static Type TypeOfObject
{
get
{
if (s_typeOfObject == null)
s_typeOfObject = typeof(object);
return s_typeOfObject;
}
}
private static Type? s_typeOfValueType;
internal static Type TypeOfValueType
{
get
{
if (s_typeOfValueType == null)
s_typeOfValueType = typeof(ValueType);
return s_typeOfValueType;
}
}
private static Type? s_typeOfArray;
internal static Type TypeOfArray
{
get
{
if (s_typeOfArray == null)
s_typeOfArray = typeof(Array);
return s_typeOfArray;
}
}

We should remove these caches, where possible, and instead just use typeof(XX) directly inline as needed. This will allow the JIT to see that the code is using runtime Type instances, and it can optimize the code if possible.

See #42824 (comment).

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Serialization untriaged New issue has not been triaged by the area owner labels Sep 29, 2020
@stephentoub stephentoub added this to the 6.0.0 milestone Sep 30, 2020
@stephentoub stephentoub removed the untriaged New issue has not been triaged by the area owner label Sep 30, 2020
@eerhardt
Copy link
Member Author

eerhardt commented Oct 1, 2020

Also consider addressing this PR comment as well: #42911 (comment)

but could we specify the parameter types in the GetMethod call?

Fully qualify the parameter types when using Reflection to find methods.

@StephenMolloy StephenMolloy modified the milestones: 6.0.0, 7.0.0 Jun 21, 2021
@StephenMolloy StephenMolloy added the Priority:3 Work that is nice to have label Sep 16, 2021
@StephenMolloy StephenMolloy modified the milestones: 7.0.0, 8.0.0 Aug 12, 2022
@HongGit HongGit modified the milestones: 8.0.0, 9.0.0 May 23, 2024
@StephenMolloy StephenMolloy modified the milestones: 9.0.0, 10.0.0 Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Serialization Priority:3 Work that is nice to have
Projects
None yet
Development

No branches or pull requests

5 participants