From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8178E38438E4; Tue, 29 Dec 2020 11:15:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8178E38438E4 From: "mscfd at gmx dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/98426] find_symbol in module.c traverses O(N) part of a search tree Date: Tue, 29 Dec 2020 11:15:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mscfd at gmx dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Dec 2020 11:15:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98426 --- Comment #3 from martin --- Sorry for the noise, but as this gives big reductions in compilation time i= t is quite important to me (and probably other big module based projects). I just realised that I mixed up gfc_symtree->name and gfc_symtree->n.sym->n= ame. The reason why find_symbol traverses the whole tree in the worst case is th= at it is ordered by gfc_symtree->name but it looks for gfc_symtree->n.sym->nam= e. So far I got the impression that either gfc_symtree->name is a unique name ("@xxx") or equal to gfc_symtree->n.sym->name (if n.sym!=3DNULL). In this c= ase, the following patch should do the trick and traverse only log(N) of the tre= e: diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 4c6ff22d5c1..8dc59e25d46 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -4659,10 +4659,20 @@ find_symbol (gfc_symtree *st, const char *name, return st; } + c =3D strcmp (name, st->name); + if (c < 0) + retval =3D find_symbol (st->left, name, module, generic); + else if (c > 0) + retval =3D find_symbol (st->right, name, module, generic); + else + retval =3D NULL; + +/* original traverse retval =3D find_symbol (st->left, name, module, generic); if (retval =3D=3D NULL) retval =3D find_symbol (st->right, name, module, generic); +*/ return retval; }=