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

Optimize unboxing in System.Data.Common.ObjectStorage:Set #91945

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,50 +236,49 @@ public override void Set(int recordNo, object value)
}
else
{
Type valType = value.GetType();
if (_dataType == typeof(Guid) && valType == typeof(string))
if (_dataType == typeof(Guid) && value is string)
{
_values[recordNo] = new Guid((string)value);
}
else if (_dataType == typeof(byte[]))
{
if (valType == typeof(bool))
if (value is bool)
Copy link
Member

Choose a reason for hiding this comment

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

nit: can use a switch expression

Copy link
Member

Choose a reason for hiding this comment

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

This may hit the performance issue logged in #47920. I actually have a branch to improve this, but it's not expandable-proof so I haven't push it.

It's also interesting to see if a following unbox.any changes the codegen of isinst.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case of a switch expression, the JIT is not able to eliminate the calls to CORINFO_HELP_UNBOX.

Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised that CORINFO_HELP_UNBOX is ever evolved after #87241.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm surprised that CORINFO_HELP_UNBOX is ever evolved after #87241.

The isinst + unbox.any optimization appears in .NET 7.

{
_values[recordNo] = BitConverter.GetBytes((bool)value);
}
else if (valType == typeof(char))
else if (value is char)
{
_values[recordNo] = BitConverter.GetBytes((char)value);
}
else if (valType == typeof(short))
else if (value is short)
{
_values[recordNo] = BitConverter.GetBytes((short)value);
}
else if (valType == typeof(int))
else if (value is int)
{
_values[recordNo] = BitConverter.GetBytes((int)value);
}
else if (valType == typeof(long))
else if (value is long)
{
_values[recordNo] = BitConverter.GetBytes((long)value);
}
else if (valType == typeof(ushort))
else if (value is ushort)
{
_values[recordNo] = BitConverter.GetBytes((ushort)value);
}
else if (valType == typeof(uint))
else if (value is uint)
{
_values[recordNo] = BitConverter.GetBytes((uint)value);
}
else if (valType == typeof(ulong))
else if (value is ulong)
{
_values[recordNo] = BitConverter.GetBytes((ulong)value);
}
else if (valType == typeof(float))
else if (value is float)
{
_values[recordNo] = BitConverter.GetBytes((float)value);
}
else if (valType == typeof(double))
else if (value is double)
{
_values[recordNo] = BitConverter.GetBytes((double)value);
}
Expand Down