public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: abenson@carnegiescience.edu
Cc: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>
Subject: Re: Optimization of add_dt_to_dt_list() in resolve.c
Date: Fri, 25 May 2018 07:13:00 -0000	[thread overview]
Message-ID: <CAFiYyc0kFzRW4YWkWKAf2iTs9j+Dyh6iUkUoCeN4zcPO_gRK-A@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc0Y_tSM-hD51iNJqHdf5QULKNX_aEDHUeeiv+EcTna17g@mail.gmail.com>

On Fri, May 25, 2018 at 9:06 AM Richard Biener <richard.guenther@gmail.com>
wrote:

> On Fri, May 25, 2018 at 12:53 AM Andrew Benson <
abenson@carnegiescience.edu>
> wrote:

> > I've been attempting to track down some of the causes of very long
compile
> > times for files which use modules that contain a large number of
symbols.
> The
> > worst case offender in my code takes around 12 minutes to compile.

> > After profiling f951 for this source file it turns out that the majority
> of the
> > time is spent in add_dt_to_dt_list() in resolve.c. In cases where the
> number
> > of symbols imported becomes very large (~10,000 in some cases in this
> code),
> > the O(N) search in this function becomes inefficient.

> > A simple optimization for this problem seems to be to just have the
> gfc_symbol
> > struct include a pointer back to the corresponding entry in the
> > gfc_derived_types list. It's then fast to check if a symbol is already
on
> that
> > list by checking if this pointer is non-null. (It could just as easily
be
> an
> > int in gfc_symbol which indicates if the symbol is already added to the
> list -
> > I don't know if having a pointer to the list entry is useful for any
other
> > reason.)

> > With this change in place compile times are much faster - my worst case
> > offender now takes just under 1 minute to compile.

> > My patch is attached. I freely admit that I have only a very shallow
> > understanding of the inner workings of the compiler, so I would not be
> > surprised if there are good reasons not to do this. I did "make
> check-fortran"
> > and did not see any failures. If any one wants to try this out and/or
> provide
> > any feedback I'd be happy to hear it.

> It looks like it would be cheaper to simply embed gtc_dt_list *next in
> gfc_symbol?
> (in case a gfc_symbol can be only on one gfc_dt_list which your patch
> assumes as well)

Note you'll need to make the list cyclic to make the member test work
as sym->next_dt != NULL.

Also note that gfc_get_derived_type has another linear list walk so it
looks like derived type processing is still quadratic in the number of
derived types after the change.  That suggests that eventually
making the derived_types list a hash-map of gfc_symbol to
the common derived type (symbol) would be a better fix, thus doing
the merging at dt-"list" insertion time.

Of course that's likely a bigger change that needs more thorough
understanding
of how derived types work.  A fix along your idea looks simple enough
and has obvious benefits as you show so it might be even appropriate for
release branches.

Richard.

> Richard.

> > Thanks,
> > Andrew

> > --

> > * Andrew Benson:
http://users.obs.carnegiescience.edu/abenson/contact.html

> > * Galacticus: https://bitbucket.org/abensonca/galacticus

  reply	other threads:[~2018-05-25  7:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24 22:53 Andrew Benson
2018-05-25  7:06 ` Richard Biener
2018-05-25  7:13   ` Richard Biener [this message]
2018-05-25 21:54   ` Andrew Benson
2018-05-28  9:54     ` Richard Biener
2018-05-29 20:25       ` Andrew Benson
2018-05-30  9:44         ` Richard Biener
2018-05-30 17:01           ` Andrew Benson
2018-05-30 18:25             ` Steve Kargl
2018-05-30 18:37               ` Andrew Benson
2018-05-30 20:43         ` Janus Weil
2018-05-30 22:22           ` Andrew Benson
2018-05-31  8:56             ` Janus Weil
2018-05-31 18:04               ` Andrew Benson
2018-06-01  6:14                 ` Janus Weil
2018-06-11 18:45                   ` Steve Kargl
2018-06-11 19:22                     ` Andrew Benson
2018-06-14  5:15                     ` Andrew Benson
2018-06-15  0:12                       ` Steve Kargl
2018-06-15  7:59                         ` Andrew Benson
2018-07-11  2:33                         ` Andrew Benson
2018-07-20 16:29                           ` Andrew Benson
2018-07-20 18:59                             ` Janus Weil
2018-07-20 19:02                               ` Andrew Benson
2018-07-20 19:10                                 ` Janus Weil
2018-07-20 20:04                                   ` Janus Weil
2018-07-20 20:22                                     ` Andrew Benson

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=CAFiYyc0kFzRW4YWkWKAf2iTs9j+Dyh6iUkUoCeN4zcPO_gRK-A@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=abenson@carnegiescience.edu \
    --cc=fortran@gcc.gnu.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).