From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.40]) by sourceware.org (Postfix) with ESMTPS id 091B9385C426 for ; Sat, 23 May 2020 21:21:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 091B9385C426 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 7E742EA055 for ; Sat, 23 May 2020 16:21:56 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id cbaejTkFW1s2xcbaejyV0q; Sat, 23 May 2020 16:21:56 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=4aKe1mPpH8COv/L7x/KW6EpZnDALYw/qv9NqArsylpc=; b=sQ6iEzsCEsnKvO3vU2o/9yk/jl JeIoiXtc8MVXh3OQGaSlw+PUeRBqahkubs4bA1V3hWrQ6ugcWZsZ+Y/8pYpU0Q8v6KARGKiRkCvUM JEyM8SsswzuKwiquXfGYGUf+q; Received: from 174-16-104-48.hlrn.qwest.net ([174.16.104.48]:35154 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jcbae-003Xjy-5s; Sat, 23 May 2020 15:21:56 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Simple speedup for DWARF CU expansion Date: Sat, 23 May 2020 15:21:54 -0600 Message-Id: <20200523212154.15024-1-tom@tromey.com> X-Mailer: git-send-email 2.17.2 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.104.48 X-Source-L: No X-Exim-ID: 1jcbae-003Xjy-5s X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-104-48.hlrn.qwest.net (bapiya.Home) [174.16.104.48]:35154 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 May 2020 21:21:58 -0000 I noticed that DWARF CU expansion had an easy-to-fix hot spot: following DIE references in dwarf2_attr. This patch fixes the problem by caching the referent in the die_info, if the two DIEs are in the same CU. (This restriction avoids any issues with CU invalidation.) I ran "gdb -readnow" on itself 10 times. The mean before on this machine was 14.522 seconds; with the patch it was 13.685 seconds. Historically I figured that CU expansion was not very important; but I think occasionally it results in unexpected delays for users. So, it's probably worth fixing. I'm not sure the micro-optimization approach is really all that good in the long run. Better, I think, would be to read types and function bodies lazily -- this would vastly improve performance. (I attempted the latter once and saw a 40% speedup, IIRC.) The use of dwarf2_attr could also be improved. Rather than looking up attributes individually, it would probably be better for (most) functions to loop once over all attributes, collecting useful information. Meanwhile, this patch seems reasonably worthwhile. gdb/ChangeLog 2020-05-23 Tom Tromey * dwarf2/read.c (dwarf2_attr): Use die_info::ref. * dwarf2/die.h (struct die_info) : New member. --- gdb/ChangeLog | 5 +++++ gdb/dwarf2/die.h | 5 +++++ gdb/dwarf2/read.c | 11 ++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/die.h b/gdb/dwarf2/die.h index 5522ebdf311..83bcdf69a17 100644 --- a/gdb/dwarf2/die.h +++ b/gdb/dwarf2/die.h @@ -94,6 +94,11 @@ struct die_info struct die_info *sibling; /* Its next sibling, if any. */ struct die_info *parent; /* Its parent, if any. */ + /* If the DIE has a DW_AT_specification or DW_AT_abstract_origin, + and the referenced DIE appears in the same CU as this DIE, then + this caches the referenced DIE. */ + struct die_info *ref; + /* An array of attributes, with NUM_ATTRS elements. There may be zero, but it's not common and zero-sized arrays are not sufficiently portable C. */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e6d08110b2a..973c6c95ded 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -19556,7 +19556,16 @@ dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) if (!spec) break; - die = follow_die_ref (die, spec, &cu); + if (die->ref != nullptr) + die = die->ref; + else + { + struct dwarf2_cu *save_cu = cu; + struct die_info *ref = follow_die_ref (die, spec, &cu); + if (cu == save_cu) + die->ref = ref; + die = ref; + } } return NULL; -- 2.17.2