public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Optimization of add_dt_to_dt_list() in resolve.c
@ 2018-05-24 22:53 Andrew Benson
  2018-05-25  7:06 ` Richard Biener
  0 siblings, 1 reply; 27+ messages in thread
From: Andrew Benson @ 2018-05-24 22:53 UTC (permalink / raw)
  To: fortran

[-- Attachment #1: Type: text/plain, Size: 1604 bytes --]

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.

Thanks,
Andrew

-- 

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

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

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 1202 bytes --]

Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 260682)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -1611,6 +1611,9 @@ typedef struct gfc_symbol
 
   /* Link to corresponding association-list if this is an associate name.  */
   struct gfc_association_list *assoc;
+
+  /* Link to derived type list */
+  struct gfc_dt_list *dt_list;
 }
 gfc_symbol;
 
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 260682)
+++ gcc/fortran/resolve.c	(working copy)
@@ -13437,14 +13437,13 @@ add_dt_to_dt_list (gfc_symbol *derived)
 {
   gfc_dt_list *dt_list;
 
-  for (dt_list = gfc_derived_types; dt_list; dt_list = dt_list->next)
-    if (derived == dt_list->derived)
-      return;
-
-  dt_list = gfc_get_dt_list ();
-  dt_list->next = gfc_derived_types;
-  dt_list->derived = derived;
-  gfc_derived_types = dt_list;
+  if (derived->dt_list == NULL) {
+    dt_list = gfc_get_dt_list ();
+    dt_list->next = gfc_derived_types;
+    dt_list->derived = derived;
+    derived->dt_list = dt_list;  
+    gfc_derived_types = dt_list;
+  }
 }
 
 

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2018-07-20 20:22 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-24 22:53 Optimization of add_dt_to_dt_list() in resolve.c Andrew Benson
2018-05-25  7:06 ` Richard Biener
2018-05-25  7:13   ` Richard Biener
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

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).