From patchwork Thu Jan 13 23:32:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 78825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 53BFDB70E0 for ; Fri, 14 Jan 2011 10:33:13 +1100 (EST) Received: (qmail 11852 invoked by alias); 13 Jan 2011 23:33:11 -0000 Received: (qmail 11836 invoked by uid 22791); 13 Jan 2011 23:33:10 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Jan 2011 23:33:03 +0000 Received: from eggs.gnu.org ([140.186.70.92]:54011) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PdWf3-00080t-V5 for gcc-patches@gnu.org; Thu, 13 Jan 2011 18:32:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdWf6-0000Nm-4j for gcc-patches@gnu.org; Thu, 13 Jan 2011 18:33:01 -0500 Received: from smtp181.iad.emailsrvr.com ([207.97.245.181]:57373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdWf6-0000NF-2F for gcc-patches@gnu.org; Thu, 13 Jan 2011 18:33:00 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp48.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id C14591694B5 for ; Thu, 13 Jan 2011 18:32:56 -0500 (EST) Received: from dynamic11.wm-web.iad.mlsrvr.com (dynamic11.wm-web.iad1a.rsapps.net [192.168.2.218]) by smtp48.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id AE0F71694B4 for ; Thu, 13 Jan 2011 18:32:56 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic11.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 8C641E0086 for ; Thu, 13 Jan 2011 18:32:56 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Fri, 14 Jan 2011 00:32:56 +0100 (CET) Date: Fri, 14 Jan 2011 00:32:56 +0100 (CET) Subject: patch: Trivial 1% speed upof ObjC compiler by reusing existing hash From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1294961576.573924085@192.168.4.58> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This trivial patch speeds up the Objective-C compiler by about 1% percent by removing the objc-act.c-specific hash function and simply using the hash value already computed by the rest of the compiler for identifiers. :-) I tested it by compiling the file #include #include int main (void) { return 0; } with GCC 4.6 (GCC 4.6 was compiled with --enable-checking=release mode) and gnustep trunk. FYI, this puts 6,649 entries in the ObjC compiler method hashtable. Without the patch, compiling it 20 times takes (over 10 measures, etc) on my machine -fsyntax-only: 2.29 +/- 0.01 units of time -g -O2: 2.96 +/- 0.01 units of time With the patch, it takes -fsyntax-only: 2.24 +/- 0.02 units of time -g -O2: 2.92 +/- 0.02 units of time It is the first time I manage to actually speed up the compiler by any measurable, reproducible amount. It's only a 1%/2% reduction in compilation times, but it is real. :-) I also tested with bigger, real Objective-C files and the reduction in compilation time is still there, of the order of 1%. Eg, goes down from 10.82 to 10.74 units of time when compiling a 1.1k line ObjC file using gnustep-base + gnustep-gui with the standard GNUstep compilation flags. I know we are in stage 4 and optimizations are not for this stage, but the patch is so obvious to me, maybe it could go in. Bootstrapped and tested. Ok to commit ? Thanks Index: objc-act.c =================================================================== --- objc-act.c (revision 168761) +++ objc-act.c (working copy) @@ -8646,19 +8646,8 @@ } /* Compute a hash value for a given method SEL_NAME. */ +#define hash_func(X) IDENTIFIER_HASH_VALUE(X) -static size_t -hash_func (tree sel_name) -{ - const unsigned char *s - = (const unsigned char *)IDENTIFIER_POINTER (sel_name); - size_t h = 0; - - while (*s) - h = h * 67 + *s++ - 113; - return h; -} - static void hash_init (void) { Index: ChangeLog =================================================================== --- ChangeLog (revision 168761) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-01-13 Nicola Pero + + * objc-act.c (hash_func): Reuse IDENTIFIER_HASH_VALUE instead of + computing a new hash value. + 2011-01-08 Iain Sandoe * objc-act.c (objc_finish_foreach_loop): Mark collection expression