patch: Trivial 1% speed upof ObjC compiler by reusing existing hash

Submitted by Nicola Pero on Jan. 13, 2011, 11:32 p.m.

Details

Message ID 1294961576.573924085@192.168.4.58
State New
Headers show

Commit Message

Nicola Pero Jan. 13, 2011, 11:32 p.m.
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 <Foundation/Foundation.h>
 #include <AppKit/AppKit.h>
 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

Comments

Mike Stump Jan. 14, 2011, 12:56 a.m.
On Jan 13, 2011, at 3:32 PM, Nicola Pero wrote:
> 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 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.
> 
> Ok to commit ?

When we hit stage1, Ok.  For this stage, I just don't think it should go in.  I'm happy to have a RM overrule me, if they choose.

Now, I might bend to rules for some types of work, like quality polishing of the new objc code...  or finishing out the implementation if there are some rough corners that just weren't completely finished.   Very important features, like, m64 darwin support, might also be worth the risk.

Patch hide | download patch | download mbox

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  <nicola.pero@meta-innovation.com>
+
+       * objc-act.c (hash_func): Reuse IDENTIFIER_HASH_VALUE instead of
+       computing a new hash value.
+
 2011-01-08  Iain Sandoe  <iains@gcc.gnu.org>
 
        * objc-act.c (objc_finish_foreach_loop): Mark collection expression