Dynamic array comparison optimization: check for equal pointers?

Stanislav Blinov stanislav.blinov at gmail.com
Wed Jun 3 02:19:03 UTC 2020


On Wednesday, 3 June 2020 at 01:10:55 UTC, Steven Schveighoffer 
wrote:

>> ....Yes? And that will fall under a hypothetical case when the 
>> check just gets removed (or heck, inserted if it's faster). 
>> Leaving it in for all other cases when the compiler *can't* 
>> remove it. Make the best case better but the worst case worse? 
>> No thanks.
>
> The worst case is opaque memcmp is called in all cases. No 
> thanks. I'll take a few extra cycles over that any day.

With the check in place, the worst case would be a useless 
comparison plus the memcmp, or a failed branch on the off chance 
that you do try to compare identical ranges. Or a useless 
comparison and a failed branch + memcmp. Depends on your program. 
Whether the effect would be significant or immeasurable - also 
depends on your program, and your data, and your hardware.

"I'm not sure what my program is doing, so let's make everyone 
else pay for it". That's what including that test, in memcmp or 
in druntime, effectively would be.


More information about the Digitalmars-d mailing list