From patchwork Mon Oct 20 21:44:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 3294 Received: (qmail 17869 invoked by alias); 20 Oct 2014 21:44:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17859 invoked by uid 89); 20 Oct 2014 21:44:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 20 Oct 2014 21:44:44 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9KLig8p017654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 20 Oct 2014 17:44:43 -0400 Received: from host2.jankratochvil.net (ovpn-116-79.ams2.redhat.com [10.36.116.79]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9KLicUB008005 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO) for ; Mon, 20 Oct 2014 17:44:41 -0400 Date: Mon, 20 Oct 2014 23:44:38 +0200 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch 1/2] Accelerate iter_match_first_hashed 1.8x Message-ID: <20141020214438.GB22011@host2.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, very simple caching. dict_hash() is being called again and again for the same string. #0 in skip_spaces_const (chp=0x7fffb10f9bb6 "ts, std::allocator >::npos") at ./cli/cli-utils.c:244 #1 in msymbol_hash_iw (string=0x7fffb10f9bb6 "ts, std::allocator >::npos") at minsyms.c:89 #2 in dict_hash ( string0=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos") at dictionary.c:840 #3 in iter_match_first_hashed (dict=0x105a7840, name=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos", compare=0x8b82f8 , iterator=0x7fffb10f9970) at dictionary.c:659 #4 in dict_iter_match_first (dict=0x105a7840, name=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos", compare=0x8b82f8 , iterator=0x7fffb10f9970) at dictionary.c:555 #5 in dict_iter_name_first (dict=0x105a7840, name=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos", iterator=0x7fffb10f9970) at dictionary.c:541 #6 in block_iter_name_step (iterator=0x7fffb10f9960, name=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos", first=1) at block.c:580 #7 in block_iter_name_first (block=0x10593e10, name=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos", iterator=0x7fffb10f9960) at block.c:609 #8 in lookup_block_symbol (block=0x10593e10, name=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos", domain=VAR_DOMAIN) at symtab.c:2062 #9 in lookup_symbol_aux_objfile (objfile=0x466f870, block_index=0, name=0x7fffb10f9b90 "std::basic_string, std::allocator >::npos", domain=VAR_DOMAIN) at symtab.c:1664 #10 in lookup_symbol_global_iterator_cb (objfile=0x466f870, cb_data=0x7fffb10f9ad0) at symtab.c:1868 Maybe it could get cached at the caller but: * We would need to pass the hash value along the whole {dict,block}_iter_* call chain. * The DICT_VECTOR virtualization would get violated as dict_linear*_vector do not use any hash values. Jan gdb/ 2014-10-20 Jan Kratochvil * dictionary.c (iter_match_first_hashed): Provide state cache for hash_index from NAME. diff --git a/gdb/dictionary.c b/gdb/dictionary.c index 055c87e..90bcd6d 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -656,9 +656,26 @@ iter_match_first_hashed (const struct dictionary *dict, const char *name, symbol_compare_ftype *compare, struct dict_iterator *iterator) { - unsigned int hash_index = dict_hash (name) % DICT_HASHED_NBUCKETS (dict); + unsigned int hash_index; struct symbol *sym; + /* Cache HASH_INDEX. */ + { + static const char *name_ptr_cached; + static char *name_content_cached; + static unsigned int dict_hash_cached; + + if (name_ptr_cached != name || strcmp (name_content_cached, name) != 0) + { + dict_hash_cached = dict_hash (name); + name_ptr_cached = name; + xfree (name_content_cached); + name_content_cached = xstrdup (name); + } + hash_index = dict_hash_cached; + } + hash_index %= DICT_HASHED_NBUCKETS (dict); + DICT_ITERATOR_DICT (iterator) = dict; /* Loop through the symbols in the given bucket, breaking when SYM