public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/4] Improve performance of Ada name searches
Date: Tue, 21 Nov 2023 14:09:25 -0700	[thread overview]
Message-ID: <20231121-ada-lookup-perf-v1-1-1efd2d1dbf65@adacore.com> (raw)
In-Reply-To: <20231121-ada-lookup-perf-v1-0-1efd2d1dbf65@adacore.com>

A user reported that certain operations -- like printing a large
structure -- could be slow.  I tracked this down to
ada-lang.c:map_matching_symbols taking an inordinate amount of time.
Specifically, calls like the one to look for a parallel "__XVZ"
variable, in ada_to_fixed_type_1, could result in gdb walking over all
the entries in the cooked index over and over.

Looking into this reveals that
cooked_index_functions::expand_matching_symbols is not written
efficiently -- it ignores its "ordered_compare" parameter.  While
fixing this would be good, it turns out that this entire method isn't
needed; so this series removes it.

However, the deletion is not done in this patch.  This one, instead,
fixes the immediate cause of the slowdown, by using
objfile::expand_symtabs_matching when possible.  This approach is
faster because it is more selective about which index entries to
examine.
---
 gdb/ada-lang.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index ff7222c7eed..8c5ab93f3ca 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5572,8 +5572,16 @@ map_matching_symbols (struct objfile *objfile,
 		      match_data &data)
 {
   data.objfile = objfile;
-  objfile->expand_matching_symbols (lookup_name, domain, global,
-				    is_wild_match ? nullptr : compare_names);
+  if (is_wild_match || lookup_name.ada ().standard_p ())
+    objfile->expand_matching_symbols (lookup_name, domain, global,
+				      is_wild_match ? nullptr : compare_names);
+  else
+    objfile->expand_symtabs_matching (nullptr, &lookup_name,
+				      nullptr, nullptr,
+				      global
+				      ? SEARCH_GLOBAL_BLOCK
+				      : SEARCH_STATIC_BLOCK,
+				      domain, ALL_DOMAIN);
 
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
   for (compunit_symtab *symtab : objfile->compunits ())

-- 
2.41.0


  reply	other threads:[~2023-11-21 21:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 21:09 [PATCH 0/4] Improve Ada name lookup performance Tom Tromey
2023-11-21 21:09 ` Tom Tromey [this message]
2023-11-21 21:09 ` [PATCH 2/4] Always use expand_symtabs_matching in ada-lang.c Tom Tromey
2023-11-21 21:09 ` [PATCH 3/4] Remove split_style::UNDERSCORE Tom Tromey
2023-11-21 21:09 ` [PATCH 4/4] Remove quick_symbol_functions::expand_matching_symbols Tom Tromey
2023-12-06 17:01 ` [PATCH 0/4] Improve Ada name lookup performance Tom Tromey
2023-12-06 17:04   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231121-ada-lookup-perf-v1-1-1efd2d1dbf65@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).