This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

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 ?


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]