-
Notifications
You must be signed in to change notification settings - Fork 286
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
Perf | avoid boxing of SqlGuid in SqlBuffer (#2300) #2306
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ internal struct Storage | |
private bool _isNull; | ||
private StorageType _type; | ||
private Storage _value; | ||
private object _object; // String, SqlBinary, SqlCachedBuffer, SqlGuid, SqlString, SqlXml | ||
private object _object; // String, SqlBinary, SqlCachedBuffer, SqlString, SqlXml | ||
|
||
internal SqlBuffer() | ||
{ | ||
|
@@ -815,14 +815,17 @@ internal SqlGuid SqlGuid | |
} | ||
else if (StorageType.SqlGuid == _type) | ||
{ | ||
return IsNull ? SqlGuid.Null : (SqlGuid)_object; | ||
return IsNull ? SqlGuid.Null : new SqlGuid(_value._guid); | ||
} | ||
return (SqlGuid)SqlValue; // anything else we haven't thought of goes through boxing. | ||
} | ||
set | ||
{ | ||
Debug.Assert(IsEmpty, "setting value a second time?"); | ||
_object = value; | ||
if (!value.IsNull) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class definitely requires its own unit tests. case StorageType.SqlBinary:
case StorageType.SqlGuid:
return _object; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what is the right place to put unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have a net8 build currently. Write the test and use the correct attribute or preprocessor definition so that when the net8 build does exist (possibly soon-ish) it will be enabled and work. Functional tests are run without a database connection. Anything that can be checked without running a query can go in there. Manual tests are run with a database connection, anything which can't be in functional tests belongs there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I vote for a revert given that a release is planned for 24 Jan - just my 2 cents There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the PR to fix that: #2310 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Wraith2 suggested to revert this PR too. See #2310 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just did a PR to revert. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we just have to wait for the MS team to work their way through the email notifications, wonder what we've all been doing all weekend, and then approve it 😁 |
||
{ | ||
_value._guid = value.Value; | ||
} | ||
_type = StorageType.SqlGuid; | ||
_isNull = value.IsNull; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you validated the outcome of this change by comparing the impact of creating a new instance versus unboxing? Overall, I'm not seeing a notable increase in efficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The efficiency isn't gained here, This is just a knockon effect. The efficiency is gained by not assigning a struct
SqlNull.Null
to an object which causes an unavoidable box every time it happens.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did perf testing and there are some performance and memory degradations brought to this getter by the PR, so, @DavoudEshtehari highlighted a valid point 👍.
I will do more perf testing and try to find a better solution in terms of memory and performance.