This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

[gmane.comp.gdb.devel] FYI: micro-optimize dwarf2_attr


I sent this to the wrong list, whoops.

--- Begin Message ---
I'm checking this in.

I was curious about CU expansion performance and I did a little
profiling today.  Normally CU expansion is not worth worrying about, but
we have found a few cases where it hurts; and so it makes sense to care
about it.

My test case was 'gdb -batch -readnow gdb'.
I reasoned (correctly) that this would be dominated by the time to
expand CUs.

This yielded a few surprises, which I have micro-optimized away.

First, dwarf2_attr can be fixed to avoid a tail-recursive call.
This reduced the time for the test case from 2.51 to 2.36.
That is about a 6% savings.

Built and regtested on x86-64 Fedora 16.

Tom

2012-03-09  Tom Tromey  <tromey@redhat.com>

	* dwarf2read.c (dwarf2_attr): Avoid tail-recursive call.

>From fa665e1aab150b3e345e8ded4219791d99ed0edb Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Fri, 9 Mar 2012 12:32:55 -0700
Subject: [PATCH 1/2] micro-optimize dwarf2_attr

---
 gdb/dwarf2read.c |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6eed8d5..9133178 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -10708,22 +10708,24 @@ set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
 static struct attribute *
 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
 {
-  unsigned int i;
-  struct attribute *spec = NULL;
-
-  for (i = 0; i < die->num_attrs; ++i)
+  for (;;)
     {
-      if (die->attrs[i].name == name)
-	return &die->attrs[i];
-      if (die->attrs[i].name == DW_AT_specification
-	  || die->attrs[i].name == DW_AT_abstract_origin)
-	spec = &die->attrs[i];
-    }
+      unsigned int i;
+      struct attribute *spec = NULL;
+
+      for (i = 0; i < die->num_attrs; ++i)
+	{
+	  if (die->attrs[i].name == name)
+	    return &die->attrs[i];
+	  if (die->attrs[i].name == DW_AT_specification
+	      || die->attrs[i].name == DW_AT_abstract_origin)
+	    spec = &die->attrs[i];
+	}
+
+      if (!spec)
+	break;
 
-  if (spec)
-    {
       die = follow_die_ref (die, spec, &cu);
-      return dwarf2_attr (die, name, cu);
     }
 
   return NULL;
-- 
1.7.7.6



--- End Message ---

Tom

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