This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcj/23495] New: java.lang.String.equals is suboptimal
- From: "greenrd at greenrd dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Aug 2005 16:23:50 -0000
- Subject: [Bug libgcj/23495] New: java.lang.String.equals is suboptimal
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I can see a way to improve the speed of java.lang.String.equals. On x86,
sizeof(void *) is 2*sizeof(jchar), whilst on x86_64, sizeof (void *) is
4*sizeof(jchar). So it should be more efficient to compare as many elements as
possible in batches of 2 (on e.g. x86) or 4 (on e.g. x86_64), by casting the
arrays to void **. (If length % 2 != 0, it is not possible to compare all the
elements in this way, of course, but all but the last can be.)
My LD_PRELOAD tests show performance improvements of up to 49% for comparing two
equal 10-character strings with this change, and up to 91% for comparing two
equal 110-character strings. There is no significant degradation for the common
case where the two strings differ in the first character, nor for the case of
very small equal strings. These results were obtained on x86 with -O2 -g
-march=athlon-xp (without -march=athlon-xp the improvements are smaller). I
would expect the improvements to be even better on x86_64, because it can
compare 4 jchars at a time.
I haven't investigated alignment issues, however. It's possible that this change
will not be faster for all arches, in which case it could be maybe #ifdef'd.
--
Summary: java.lang.String.equals is suboptimal
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: greenrd at greenrd dot org
CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23495