[PATCH] Improve qsort_cmp performance by memoizing objfile data

Tom Tromey tom@tromey.com
Tue Aug 20 15:16:00 GMT 2019

>>>>> "Vijay" == Vijay Klein <vijaygk2@illinois.edu> writes:

Vijay> RATIONALE: The rationale behind this patch is that, currently, the
Vijay> qsort_cmp function can fall into a default case where it linearly
Vijay> traverses all the objfiles.

Thank you for the patch.

I'm curious if you have seen this code path taken.

Vijay> FSF Copyright Assignment: To be completely honest, I'm not entirely
Vijay> sure what is required here. I designed and wrote the entire change, if
Vijay> that is relevant. On the contribution checklist, it said the reviewer
Vijay> would send me the proper form, so all help is appreciated!

I don't think I have the forms available any more.  Maybe one of the
other maintainers can email you the appropriate one; or you can email
assign@gnu for the paperwork.

Vijay> +  int index;
Vijay> -  section = &objfile->sections[gdb_bfd_section_index (abfd, asect)];
Vijay> +  index = gdb_bfd_section_index (abfd, asect);

Better nowadays to just write "int index = ...".

Vijay> +/* Must be called whenever the order of the linked list is edited, to ensure
Vijay> +   the comparison function has up to date info. Freeing an objfile does not
Vijay> +   require this function, as the order is maintained, but a function like
Vijay> +   `put_objfile_before` should certainly call this.  */
Vijay> +void
Vijay> +update_objfile_ids (void)

It seems to me that there isn't a deep reason to prefer exactly the
order of the objfiles in the list -- any consistent order seems fine.
So, how about just setting the objfile's "id" at creation time, and
using that?

Then this function wouldn't be needed.

Vijay> +  /* Memoized BFD section index returned from gdb_bfd_section_index  */
Vijay> +  int index;

GNU style is to have a period (followed by 2 spaces) at the end of

Vijay> +  /* A unique sequence identifier for the global linked list */

Here too.


More information about the Gdb-patches mailing list