From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29684 invoked by alias); 20 Aug 2005 16:23:50 -0000 Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org Received: (qmail 29666 invoked by uid 48); 20 Aug 2005 16:23:50 -0000 Date: Sat, 20 Aug 2005 16:23:00 -0000 From: "greenrd at greenrd dot org" To: java-prs@gcc.gnu.org Message-ID: <20050820162349.23495.greenrd@greenrd.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libgcj/23495] New: java.lang.String.equals is suboptimal X-Bugzilla-Reason: CC X-SW-Source: 2005-q3/txt/msg00297.txt.bz2 List-Id: 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