Bug #68477 Suboptimal code in skip_trailing_space()
Submitted: 24 Feb 2013 5:57 Modified: 8 May 2013 2:54
Reporter: Alexey Kopytov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.1, 5.5, 5.6 OS:Any
Assigned to: Tor Didriksen CPU Architecture:Any

[24 Feb 2013 5:57] Alexey Kopytov
Description:
The skip_trailing_space() implementation is suboptimal. 2 problems:

- it assumes SIZEOF_INT to be the machine word length. So it processes
  the string by 4-byte words even on 64-bit machines. It should
  actually be SIZEOF_LONG as it's normally the real machine word length.

- it is unnecessary brachy. Too many "if"s and loops for such a simple code.

How to repeat:
Look at skip_trailing_space().
[25 Feb 2013 13:48] MySQL Verification Team
Thank you for the bug report.
[16 Apr 2013 14:38] Tor Didriksen
All this alignment stuff is really only necessary on Sparc.
Simply looping, and dereferencing (end-8) as an ulonglong* 
is roughly twice as fast as the original implementation.

Removing the un-necessary if (end_words > ptr)
saves a little bit.
Switching to 8 byte reads saves time for most types of input
it there's more than ~100 bytes of whitespace to remove.
[8 May 2013 2:54] Paul DuBois
Noted in 5.7.2 changelog.

Overhead for the skip_trailing_space() function was reduced.