Bug #14638 | ptr_compare processes data only byte wise | ||
---|---|---|---|
Submitted: | 4 Nov 2005 13:10 | Modified: | 12 Dec 2009 15:41 |
Reporter: | Gunnar von Boehn | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: General | Severity: | S5 (Performance) |
Version: | 5.0-BK, 5.1.43-bzr | OS: | Any (any) |
Assigned to: | Assigned Account | CPU Architecture: | Any |
[4 Nov 2005 13:10]
Gunnar von Boehn
[4 Nov 2005 13:28]
Valeriy Kravchuk
In current 5.0-BK sources (ChangeSet@1.1957.1.18, 2005-11-03 20:29:21+02:00, jani@ua141d10.elisa.omakaista.fi) one may find the following in mysys/ptr_cmp.c (NOT ptr_compare.c): static int ptr_compare(uint *compare_length, uchar **a, uchar **b) { reg3 int length= *compare_length; reg1 uchar *first,*last; first= *a; last= *b; while (--length) { if (*first++ != *last++) return (int) first[-1] - (int) last[-1]; } return (int) first[0] - (int) last[0]; } If it can be optimized for some plafroms - great! Let it be...
[20 Feb 2008 12:36]
Martin Hansson
Benchmark comparing memory comparison performance.
Attachment: bug14638.test (application/octet-stream, text), 787 bytes.
[20 Feb 2008 12:36]
Martin Hansson
I don't believe it is worthwhile hand-optimizing library functions. Especially since gcc versions after 4.1.2 inline their own versions of them. Following is a patch that replaces our hand-turned copy routine with a wrapper for memcmp. However, the attached benchmark gives a slightly worse performance for it. Benchmark run on a 32 bit Pentium Core2 Quad. unfixed: 32.811 memcmp: 36.595 s
[20 Feb 2008 12:53]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/42642 ChangeSet@1.2594, 2008-02-20 13:44:15+01:00, mhansson@riffraff.(none) +4 -0 Bug#14638: ptr_compare processes data only byte wise The comparison function for memory regions is not the optimal way to compare memory regions on modern architectures. This patch replaces the hand-optimized function with a wrapper for memcmp, which is inlined in gcc versions >= 4.1.2.
[20 Feb 2008 12:54]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/42643 ChangeSet@1.2594, 2008-02-20 13:51:23+01:00, mhansson@riffraff.(none) +4 -0 Bug#14638: ptr_compare processes data only byte wise The comparison function for memory regions is not the optimal way to compare memory regions on modern architectures. This patch replaces the hand-optimized function with a wrapper for memcmp, which is inlined in gcc versions >= 4.1.2.
[19 Jun 2008 8:56]
Martin Hansson
It is the general consensus that we should not try and implement our own memcmp's. It is not a current priority.
[12 Dec 2009 15:41]
Valeriy Kravchuk
In current 5.1.43 from bzr ptr_compare still looks the same for all platforms: static int ptr_compare(size_t *compare_length, uchar **a, uchar **b) { reg3 int length= *compare_length; reg1 uchar *first,*last; first= *a; last= *b; while (--length) { if (*first++ != *last++) return (int) first[-1] - (int) last[-1]; } return (int) first[0] - (int) last[0]; }