]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Create a correctly-sized demangled names hashtable
authorChristian Biesinger <cbiesinger@google.com>
Mon, 18 Nov 2019 22:37:31 +0000 (16:37 -0600)
committerChristian Biesinger <cbiesinger@google.com>
Mon, 18 Nov 2019 23:51:10 +0000 (17:51 -0600)
If we have a minsym count, we know the demangled names hashtable will
be at least that big.  So use that count to create it, so we don't
have to resize/rehash it as much.

This is a 6% improvement in minsym loading time.

2019-11-18  Christian Biesinger  <cbiesinger@google.com>

* symtab.c (create_demangled_names_hash): Use per_bfd->
minimal_symbol_count as the initial size, if greater than
our default size.

Change-Id: I1f074d38e1d90af58705ec852f90c84cc034cd2e

gdb/symtab.c

index 9d6f33d4525e247b9290fc4e5801bba500f900be..77db501a4ca2741616e97f9c97101b54cfd7f038 100644 (file)
@@ -770,10 +770,17 @@ create_demangled_names_hash (struct objfile_per_bfd_storage *per_bfd)
   /* Choose 256 as the starting size of the hash table, somewhat arbitrarily.
      The hash table code will round this up to the next prime number.
      Choosing a much larger table size wastes memory, and saves only about
-     1% in symbol reading.  */
+     1% in symbol reading.  However, if the minsym count is already
+     initialized (e.g. because symbol name setting was deferred to
+     a background thread) we can initialize the hashtable with that
+     count, because we will almost certainly have at least that
+     many entries.  If we have a nonzero number but less than 256,
+     we still stay with 256 to have some space for psymbols, etc.  */
+
+  int count = std::max (per_bfd->minimal_symbol_count, 256);
 
   per_bfd->demangled_names_hash.reset (htab_create_alloc
-    (256, hash_demangled_name_entry, eq_demangled_name_entry,
+    (count, hash_demangled_name_entry, eq_demangled_name_entry,
      free_demangled_name_entry, xcalloc, xfree));
 }