Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)
Tab completion when debugging a program binary that uses GDB index is
surprisingly much slower than when GDB uses psymtabs instead. Around
1.5x/3x slower. That's surprising, because the whole point of GDB
index is to speed things up...
For example, with:
set pagination off
set $count = 0
while $count < 400
complete b string_prin # matches gdb's string_printf
printf "count = %d\n", $count
set $count = $count + 1
end
$ time ./gdb --batch -q ./gdb-with-index -ex "source script.cmd"
real 0m11.042s
user 0m10.920s
sys 0m0.042s
$ time ./gdb --batch -q ./gdb-without-index -ex "source script.cmd"
real 0m4.635s
user 0m4.590s
sys 0m0.037s
Same but with:
- complete b string_prin
+ complete b zzzzzz
to exercise the no-matches worst case, master currently gets you
something like:
with index without index
real 0m11.971s 0m8.413s
user 0m11.912s 0m8.355s
sys 0m0.035s 0m0.035s
Running gdb under perf shows 80% spent inside
maybe_add_partial_symtab_filename, and 20% spent in the lbasename
inside that.
The problem that tab completion walks over all compunit symtabs, and
for each, walks the contained file symtabs. And there a huge number
of file symtabs (each included system header, etc.) that appear in
each compunit symtab's file symtab list. As in, when debugging GDB, I
have 367381 symtabs iterated, when of those only 5371 filenames are
unique...
This was a regression from the earlier (nice) split of symtabs in
compunit symtabs + file symtabs.
The fix here is to add a cache of unique filenames per objfile so that
the walk / uniquing is only done once. There's already a abstraction
for this in symtab.c; this patch moves that code out to a separate
file and C++ifies it bit.
This makes the worst-case scenario above consistently drop to ~2.5s
(1.5s for the "string_prin" hit case), making it over 3.3x times
faster than psymtabs in this use case (7x in the "string_prin" hit
case).
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* Makefile.in (COMMON_OBS): Add filename-seen-cache.o.
* dwarf2read.c: Include "filename-seen-cache.h".
* dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field.
(dw2_map_symbol_filenames): Build and use a filenames_seen_cache.
* filename-seen-cache.c: New file.
* filename-seen-cache.h: New file.
* symtab.c: Include "filename-seen-cache.h".
(struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE)
(create_filename_seen_cache, clear_filename_seen_cache)
(delete_filename_seen_cache, filename_seen): Delete, parts moved
to filename-seen-cache.h/filename-seen-cache.c.
(output_source_filename, sources_info)
(maybe_add_partial_symtab_filename)
(make_source_files_completion_list): Adjust to use
filename_seen_cache.
2017-07-17 18:28:33 +08:00
|
|
|
/* Filename-seen cache for the GNU debugger, GDB.
|
|
|
|
|
2022-01-01 22:56:03 +08:00
|
|
|
Copyright (C) 1986-2022 Free Software Foundation, Inc.
|
Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)
Tab completion when debugging a program binary that uses GDB index is
surprisingly much slower than when GDB uses psymtabs instead. Around
1.5x/3x slower. That's surprising, because the whole point of GDB
index is to speed things up...
For example, with:
set pagination off
set $count = 0
while $count < 400
complete b string_prin # matches gdb's string_printf
printf "count = %d\n", $count
set $count = $count + 1
end
$ time ./gdb --batch -q ./gdb-with-index -ex "source script.cmd"
real 0m11.042s
user 0m10.920s
sys 0m0.042s
$ time ./gdb --batch -q ./gdb-without-index -ex "source script.cmd"
real 0m4.635s
user 0m4.590s
sys 0m0.037s
Same but with:
- complete b string_prin
+ complete b zzzzzz
to exercise the no-matches worst case, master currently gets you
something like:
with index without index
real 0m11.971s 0m8.413s
user 0m11.912s 0m8.355s
sys 0m0.035s 0m0.035s
Running gdb under perf shows 80% spent inside
maybe_add_partial_symtab_filename, and 20% spent in the lbasename
inside that.
The problem that tab completion walks over all compunit symtabs, and
for each, walks the contained file symtabs. And there a huge number
of file symtabs (each included system header, etc.) that appear in
each compunit symtab's file symtab list. As in, when debugging GDB, I
have 367381 symtabs iterated, when of those only 5371 filenames are
unique...
This was a regression from the earlier (nice) split of symtabs in
compunit symtabs + file symtabs.
The fix here is to add a cache of unique filenames per objfile so that
the walk / uniquing is only done once. There's already a abstraction
for this in symtab.c; this patch moves that code out to a separate
file and C++ifies it bit.
This makes the worst-case scenario above consistently drop to ~2.5s
(1.5s for the "string_prin" hit case), making it over 3.3x times
faster than psymtabs in this use case (7x in the "string_prin" hit
case).
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* Makefile.in (COMMON_OBS): Add filename-seen-cache.o.
* dwarf2read.c: Include "filename-seen-cache.h".
* dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field.
(dw2_map_symbol_filenames): Build and use a filenames_seen_cache.
* filename-seen-cache.c: New file.
* filename-seen-cache.h: New file.
* symtab.c: Include "filename-seen-cache.h".
(struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE)
(create_filename_seen_cache, clear_filename_seen_cache)
(delete_filename_seen_cache, filename_seen): Delete, parts moved
to filename-seen-cache.h/filename-seen-cache.c.
(output_source_filename, sources_info)
(maybe_add_partial_symtab_filename)
(make_source_files_completion_list): Adjust to use
filename_seen_cache.
2017-07-17 18:28:33 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "filename-seen-cache.h"
|
|
|
|
#include "filenames.h"
|
|
|
|
|
|
|
|
/* Initial size of the table. It automagically grows from here. */
|
|
|
|
#define INITIAL_FILENAME_SEEN_CACHE_SIZE 100
|
|
|
|
|
|
|
|
/* filename_seen_cache constructor. */
|
|
|
|
|
|
|
|
filename_seen_cache::filename_seen_cache ()
|
2020-09-18 01:47:50 +08:00
|
|
|
: m_tab (htab_create_alloc (INITIAL_FILENAME_SEEN_CACHE_SIZE,
|
|
|
|
filename_hash, filename_eq,
|
|
|
|
NULL, xcalloc, xfree))
|
Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)
Tab completion when debugging a program binary that uses GDB index is
surprisingly much slower than when GDB uses psymtabs instead. Around
1.5x/3x slower. That's surprising, because the whole point of GDB
index is to speed things up...
For example, with:
set pagination off
set $count = 0
while $count < 400
complete b string_prin # matches gdb's string_printf
printf "count = %d\n", $count
set $count = $count + 1
end
$ time ./gdb --batch -q ./gdb-with-index -ex "source script.cmd"
real 0m11.042s
user 0m10.920s
sys 0m0.042s
$ time ./gdb --batch -q ./gdb-without-index -ex "source script.cmd"
real 0m4.635s
user 0m4.590s
sys 0m0.037s
Same but with:
- complete b string_prin
+ complete b zzzzzz
to exercise the no-matches worst case, master currently gets you
something like:
with index without index
real 0m11.971s 0m8.413s
user 0m11.912s 0m8.355s
sys 0m0.035s 0m0.035s
Running gdb under perf shows 80% spent inside
maybe_add_partial_symtab_filename, and 20% spent in the lbasename
inside that.
The problem that tab completion walks over all compunit symtabs, and
for each, walks the contained file symtabs. And there a huge number
of file symtabs (each included system header, etc.) that appear in
each compunit symtab's file symtab list. As in, when debugging GDB, I
have 367381 symtabs iterated, when of those only 5371 filenames are
unique...
This was a regression from the earlier (nice) split of symtabs in
compunit symtabs + file symtabs.
The fix here is to add a cache of unique filenames per objfile so that
the walk / uniquing is only done once. There's already a abstraction
for this in symtab.c; this patch moves that code out to a separate
file and C++ifies it bit.
This makes the worst-case scenario above consistently drop to ~2.5s
(1.5s for the "string_prin" hit case), making it over 3.3x times
faster than psymtabs in this use case (7x in the "string_prin" hit
case).
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* Makefile.in (COMMON_OBS): Add filename-seen-cache.o.
* dwarf2read.c: Include "filename-seen-cache.h".
* dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field.
(dw2_map_symbol_filenames): Build and use a filenames_seen_cache.
* filename-seen-cache.c: New file.
* filename-seen-cache.h: New file.
* symtab.c: Include "filename-seen-cache.h".
(struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE)
(create_filename_seen_cache, clear_filename_seen_cache)
(delete_filename_seen_cache, filename_seen): Delete, parts moved
to filename-seen-cache.h/filename-seen-cache.c.
(output_source_filename, sources_info)
(maybe_add_partial_symtab_filename)
(make_source_files_completion_list): Adjust to use
filename_seen_cache.
2017-07-17 18:28:33 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See filename-seen-cache.h. */
|
|
|
|
|
|
|
|
void
|
|
|
|
filename_seen_cache::clear ()
|
|
|
|
{
|
2020-09-18 01:47:50 +08:00
|
|
|
htab_empty (m_tab.get ());
|
Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)
Tab completion when debugging a program binary that uses GDB index is
surprisingly much slower than when GDB uses psymtabs instead. Around
1.5x/3x slower. That's surprising, because the whole point of GDB
index is to speed things up...
For example, with:
set pagination off
set $count = 0
while $count < 400
complete b string_prin # matches gdb's string_printf
printf "count = %d\n", $count
set $count = $count + 1
end
$ time ./gdb --batch -q ./gdb-with-index -ex "source script.cmd"
real 0m11.042s
user 0m10.920s
sys 0m0.042s
$ time ./gdb --batch -q ./gdb-without-index -ex "source script.cmd"
real 0m4.635s
user 0m4.590s
sys 0m0.037s
Same but with:
- complete b string_prin
+ complete b zzzzzz
to exercise the no-matches worst case, master currently gets you
something like:
with index without index
real 0m11.971s 0m8.413s
user 0m11.912s 0m8.355s
sys 0m0.035s 0m0.035s
Running gdb under perf shows 80% spent inside
maybe_add_partial_symtab_filename, and 20% spent in the lbasename
inside that.
The problem that tab completion walks over all compunit symtabs, and
for each, walks the contained file symtabs. And there a huge number
of file symtabs (each included system header, etc.) that appear in
each compunit symtab's file symtab list. As in, when debugging GDB, I
have 367381 symtabs iterated, when of those only 5371 filenames are
unique...
This was a regression from the earlier (nice) split of symtabs in
compunit symtabs + file symtabs.
The fix here is to add a cache of unique filenames per objfile so that
the walk / uniquing is only done once. There's already a abstraction
for this in symtab.c; this patch moves that code out to a separate
file and C++ifies it bit.
This makes the worst-case scenario above consistently drop to ~2.5s
(1.5s for the "string_prin" hit case), making it over 3.3x times
faster than psymtabs in this use case (7x in the "string_prin" hit
case).
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* Makefile.in (COMMON_OBS): Add filename-seen-cache.o.
* dwarf2read.c: Include "filename-seen-cache.h".
* dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field.
(dw2_map_symbol_filenames): Build and use a filenames_seen_cache.
* filename-seen-cache.c: New file.
* filename-seen-cache.h: New file.
* symtab.c: Include "filename-seen-cache.h".
(struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE)
(create_filename_seen_cache, clear_filename_seen_cache)
(delete_filename_seen_cache, filename_seen): Delete, parts moved
to filename-seen-cache.h/filename-seen-cache.c.
(output_source_filename, sources_info)
(maybe_add_partial_symtab_filename)
(make_source_files_completion_list): Adjust to use
filename_seen_cache.
2017-07-17 18:28:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* See filename-seen-cache.h. */
|
|
|
|
|
|
|
|
bool
|
|
|
|
filename_seen_cache::seen (const char *file)
|
|
|
|
{
|
|
|
|
void **slot;
|
|
|
|
|
|
|
|
/* Is FILE in tab? */
|
2020-09-18 01:47:50 +08:00
|
|
|
slot = htab_find_slot (m_tab.get (), file, INSERT);
|
Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)
Tab completion when debugging a program binary that uses GDB index is
surprisingly much slower than when GDB uses psymtabs instead. Around
1.5x/3x slower. That's surprising, because the whole point of GDB
index is to speed things up...
For example, with:
set pagination off
set $count = 0
while $count < 400
complete b string_prin # matches gdb's string_printf
printf "count = %d\n", $count
set $count = $count + 1
end
$ time ./gdb --batch -q ./gdb-with-index -ex "source script.cmd"
real 0m11.042s
user 0m10.920s
sys 0m0.042s
$ time ./gdb --batch -q ./gdb-without-index -ex "source script.cmd"
real 0m4.635s
user 0m4.590s
sys 0m0.037s
Same but with:
- complete b string_prin
+ complete b zzzzzz
to exercise the no-matches worst case, master currently gets you
something like:
with index without index
real 0m11.971s 0m8.413s
user 0m11.912s 0m8.355s
sys 0m0.035s 0m0.035s
Running gdb under perf shows 80% spent inside
maybe_add_partial_symtab_filename, and 20% spent in the lbasename
inside that.
The problem that tab completion walks over all compunit symtabs, and
for each, walks the contained file symtabs. And there a huge number
of file symtabs (each included system header, etc.) that appear in
each compunit symtab's file symtab list. As in, when debugging GDB, I
have 367381 symtabs iterated, when of those only 5371 filenames are
unique...
This was a regression from the earlier (nice) split of symtabs in
compunit symtabs + file symtabs.
The fix here is to add a cache of unique filenames per objfile so that
the walk / uniquing is only done once. There's already a abstraction
for this in symtab.c; this patch moves that code out to a separate
file and C++ifies it bit.
This makes the worst-case scenario above consistently drop to ~2.5s
(1.5s for the "string_prin" hit case), making it over 3.3x times
faster than psymtabs in this use case (7x in the "string_prin" hit
case).
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* Makefile.in (COMMON_OBS): Add filename-seen-cache.o.
* dwarf2read.c: Include "filename-seen-cache.h".
* dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field.
(dw2_map_symbol_filenames): Build and use a filenames_seen_cache.
* filename-seen-cache.c: New file.
* filename-seen-cache.h: New file.
* symtab.c: Include "filename-seen-cache.h".
(struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE)
(create_filename_seen_cache, clear_filename_seen_cache)
(delete_filename_seen_cache, filename_seen): Delete, parts moved
to filename-seen-cache.h/filename-seen-cache.c.
(output_source_filename, sources_info)
(maybe_add_partial_symtab_filename)
(make_source_files_completion_list): Adjust to use
filename_seen_cache.
2017-07-17 18:28:33 +08:00
|
|
|
if (*slot != NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* No; add it to tab. */
|
|
|
|
*slot = (char *) file;
|
|
|
|
return false;
|
|
|
|
}
|