public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/23495] New: java.lang.String.equals is suboptimal
@ 2005-08-20 16:23 greenrd at greenrd dot org
  2005-08-20 16:29 ` [Bug libgcj/23495] " greenrd at greenrd dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: greenrd at greenrd dot org @ 2005-08-20 16:23 UTC (permalink / raw)
  To: java-prs

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-03-10  0:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-23495-11308@http.gcc.gnu.org/bugzilla/>
2006-02-06 22:12 ` [Bug libgcj/23495] java.lang.String.equals is suboptimal tromey at gcc dot gnu dot org
2006-03-08  0:54 ` tromey at gcc dot gnu dot org
2006-03-08 14:39 ` greenrd at gcc dot gnu dot org
2006-03-09 19:17 ` tromey at gcc dot gnu dot org
2006-03-10  0:39 ` tromey at gcc dot gnu dot org
2006-03-10  0:48 ` tromey at gcc dot gnu dot org
2005-08-20 16:23 [Bug libgcj/23495] New: " greenrd at greenrd dot org
2005-08-20 16:29 ` [Bug libgcj/23495] " greenrd at greenrd dot org
2005-08-20 19:10 ` pinskia at gcc dot gnu dot org
2005-08-20 19:41 ` pinskia at gcc dot gnu dot org
2005-08-22 21:54 ` tromey at gcc dot gnu dot org
2005-08-28 23:25 ` greenrd at greenrd dot org
2005-08-28 23:32 ` pinskia at physics dot uc dot edu
2005-08-30  1:17 ` greenrd at greenrd dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).