-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Avoid unnecessary work for identical locations in Buffer.BlockCopy #36
Conversation
Could you also update the commit message to follow the published guidelines? https://github.com/dotnet/corefx/wiki/Contributing#commits |
if (count > 0) { | ||
memmove(dst->GetDataPtr() + dstOffset, src->GetDataPtr() + srcOffset, count); | ||
if ((srcPtr != dstPtr) && (count > 0)) { | ||
memmove(dstPtr, srcPtr, count); | ||
} | ||
|
||
FC_GC_POLL(); |
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.
Should FC_GC_POLL() also be moved inside the if test, i.e. only run when work is done?
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.
FC_GC_POLL should be done all the time even when no work is done. Otherwise, there is a risk of GC starvation - the suspension for GC would take hang if there is a thread that calls BlockCopy in a tight loop.
Could you please update the commit message to something like "Avoid unnecessary work for identical locations in Buffer.BlockCopy" so that it follows the guidelines that Alex mentioned above? |
Done |
LGTM |
LGTM -- would you mind squashing the commits? Then we are good to go! |
Perform validity checks to ensure parameters are correct but short-circuit out memmove when exactly the same data would be copied to the same location. There are a number of occasions; which can be intentional or unintentional, where the buffer being copied is the same place - e.g an internal buffer is the same as the return buffer, and there is no need to call memmove's overwrite safe copy. Generally the call to BlockCopy will be in a library so it is more practical to enable the check here rather than alter all the calling functions, including 3rd party libraries to preform additional checks.
Squashed |
Avoid unnecessary work for identical locations in Buffer.BlockCopy
Thanks for the contribution! |
Port some fixes to ARM64.
We end up draining the relevant bucket in the pool very quickly, such that we still end up doing a lot of allocating while also harming other users of the same bucket size.
Avoid unnecessary work for identical locations in Buffer.BlockCopy
Perform validity checks to ensure parameters are correct but short-circuit
out memmove when exactly the same data would be copied to the same location.
There are a number of occasions; which can be intentional or unintentional,
where the buffer being copied is the same place - e.g an internal buffer is
the same as the return buffer, and there is no need to call memmove's
overwrite safe copy.
Generally the call to BlockCopy will be in a library so it is more practical
to enable the check here rather than alter all the calling functions,
including 3rd party libraries to preform additional checks.