public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "greenrd at greenrd dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libgcj/23495] New: java.lang.String.equals is suboptimal
Date: Sat, 20 Aug 2005 16:29:00 -0000	[thread overview]
Message-ID: <20050820162349.23495.greenrd@greenrd.org> (raw)

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


             reply	other threads:[~2005-08-20 16:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-20 16:29 greenrd at greenrd dot org [this message]
2005-08-20 16:35 ` [Bug libgcj/23495] " greenrd at greenrd dot org
2005-08-20 19:18 ` pinskia at gcc dot gnu dot org
2005-08-20 19:58 ` pinskia at gcc dot gnu dot org
2005-08-22 22:03 ` tromey at gcc dot gnu dot org
2005-08-28 23:32 ` greenrd at greenrd dot org
2005-08-28 23:32   ` Andrew Pinski
2005-08-28 23:36 ` pinskia at physics dot uc dot edu
2005-08-30  2:09 ` greenrd at greenrd dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050820162349.23495.greenrd@greenrd.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).