From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112626 invoked by alias); 20 Aug 2018 22:31:14 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 112552 invoked by uid 89); 20 Aug 2018 22:31:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:sk:k19-v6s, rapidly, contacthtml, contact.html X-HELO: mail-pf1-f174.google.com Received: from mail-pf1-f174.google.com (HELO mail-pf1-f174.google.com) (209.85.210.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Aug 2018 22:31:03 +0000 Received: by mail-pf1-f174.google.com with SMTP id k19-v6so7483854pfi.1 for ; Mon, 20 Aug 2018 15:31:03 -0700 (PDT) Return-Path: Received: from andrew-precision-3520.localnet ([2600:1012:b06e:91d5:b:3381:a515:6ec6]) by smtp.gmail.com with ESMTPSA id n9-v6sm15487644pfg.21.2018.08.20.15.31.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 15:31:00 -0700 (PDT) From: Andrew Benson To: "fortran@gcc.gnu.org" Subject: Optimization in load_generic_interfaces() Date: Mon, 20 Aug 2018 22:31:00 -0000 Message-ID: <2839679.PxYyRMJBjJ@andrew-precision-3520> User-Agent: KMail/5.2.3 (Linux/4.4.0-131-generic; KDE/5.36.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart383703767.VzUOSUGFX8" Content-Transfer-Encoding: 7Bit X-IsSubscribed: yes X-SW-Source: 2018-08/txt/msg00075.txt.bz2 This is a multi-part message in MIME format. --nextPart383703767.VzUOSUGFX8 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 2150 I'm continuing to look for optimizations to improve compile times for files which USE large numbers of modules containing large numbers of symbols. When the number of symbols becomes very large, find_symbol() becomes a slow- point, because it can't use the structure of the balanced binary tree to rapidly search the symtree, so just has to go through the whole tree until it finds (or doesn't find) the symbol. I don't see a simple way to improve the speed of this function, but there seems to be a simple change in load_generic_interfaces() which gives significant speed up: Index: gcc/fortran/module.c =================================================================== --- gcc/fortran/module.c (revision 263667) +++ gcc/fortran/module.c (working copy) @@ -4559,9 +4559,6 @@ load_generic_interfaces (void) /* Decide if we need to load this one or not. */ p = find_use_name_n (name, &i, false); - st = find_symbol (gfc_current_ns->sym_root, - name, module_name, 1); - if (!p || gfc_find_symbol (p, NULL, 0, &sym)) { /* Skip the specific names for these cases. */ @@ -4570,6 +4567,9 @@ load_generic_interfaces (void) continue; } + st = find_symbol (gfc_current_ns->sym_root, + name, module_name, 1); + /* If the symbol exists already and is being USEd without being in an ONLY clause, do not load a new symtree(11.3.2). */ if (!only_flag && st) This just delays the call to find_symbol() until after the first test of whether the symbol needs to be loaded - if that test fails then find_symbol() is never called. This has no significant effect on compile time for files which import small numbers of symbols. But for cases where the number is large I find that the compile time can be reduced by up to 40% in the cases I've tried. The change passes all regression tests cleanly. -Andrew -- * Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html * Galacticus: https://bitbucket.org/abensonca/galacticus --nextPart383703767.VzUOSUGFX8 Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="patch.diff" Content-length: 847 Index: gcc/fortran/module.c =================================================================== --- gcc/fortran/module.c (revision 263667) +++ gcc/fortran/module.c (working copy) @@ -4559,9 +4559,6 @@ load_generic_interfaces (void) /* Decide if we need to load this one or not. */ p = find_use_name_n (name, &i, false); - st = find_symbol (gfc_current_ns->sym_root, - name, module_name, 1); - if (!p || gfc_find_symbol (p, NULL, 0, &sym)) { /* Skip the specific names for these cases. */ @@ -4570,6 +4567,9 @@ load_generic_interfaces (void) continue; } + st = find_symbol (gfc_current_ns->sym_root, + name, module_name, 1); + /* If the symbol exists already and is being USEd without being in an ONLY clause, do not load a new symtree(11.3.2). */ if (!only_flag && st) --nextPart383703767.VzUOSUGFX8 Content-Disposition: attachment; filename="ChangeLog" Content-Transfer-Encoding: 7Bit Content-Type: text/x-changelog; charset="UTF-8"; name="ChangeLog" Content-length: 165 2018-08-20 Andrew Benson * module.c (load_generic_interfaces): Move call to find_symbol() so that only occurs if actually needed. --nextPart383703767.VzUOSUGFX8--