From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.bugs Subject: bug#41354: equal? has no sensible code path for symbols Date: Thu, 28 May 2020 18:50:20 +0200 Message-ID: <87blm8c8c3.fsf@fencepost.gnu.org> References: <87v9kuzvht.fsf@fencepost.gnu.org> <875zchjen4.fsf@gnu.org> <87o8q9cddl.fsf@fencepost.gnu.org> <87367kavs1.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="112543"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 41354@debbugs.gnu.org To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Thu May 28 18:51:08 2020 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeLkI-000TB5-So for guile-bugs@m.gmane-mx.org; Thu, 28 May 2020 18:51:06 +0200 Original-Received: from localhost ([::1]:47392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeLkH-0007cB-Vc for guile-bugs@m.gmane-mx.org; Thu, 28 May 2020 12:51:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeLkE-0007bq-0s for bug-guile@gnu.org; Thu, 28 May 2020 12:51:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41385) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeLkD-0004HN-OA for bug-guile@gnu.org; Thu, 28 May 2020 12:51:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jeLkD-00061Y-M1 for bug-guile@gnu.org; Thu, 28 May 2020 12:51:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Kastrup Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 28 May 2020 16:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41354 X-GNU-PR-Package: guile Original-Received: via spool by 41354-submit@debbugs.gnu.org id=B41354.159068463223115 (code B ref 41354); Thu, 28 May 2020 16:51:01 +0000 Original-Received: (at 41354) by debbugs.gnu.org; 28 May 2020 16:50:32 +0000 Original-Received: from localhost ([127.0.0.1]:52931 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jeLjk-00060l-2L for submit@debbugs.gnu.org; Thu, 28 May 2020 12:50:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36678) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jeLji-00060X-Af for 41354@debbugs.gnu.org; Thu, 28 May 2020 12:50:30 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:36745) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeLjc-0003jw-8Y; Thu, 28 May 2020 12:50:24 -0400 Original-Received: from x5d859cc4.dyn.telefonica.de ([93.133.156.196]:37826 helo=lola) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jeLjb-0003OT-QZ; Thu, 28 May 2020 12:50:24 -0400 In-Reply-To: <87367kavs1.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Thu, 28 May 2020 18:06:54 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:9788 Archived-At: Ludovic Court=C3=A8s writes: > David Kastrup skribis: > >> Ludovic Court=C3=A8s writes: >> >>> Hi David, >>> >>> David Kastrup skribis: >> >> Symbols comparing as _unequal_ have no special path in equal?. > > I was going to say that this is necessary for uninterned symbols, but it > turns out that uninterned symbols that look the same are not =E2=80=98equ= al?=E2=80=99: > > scheme@(guile-user)> (define a (make-symbol "x")) > scheme@(guile-user)> (define b (make-symbol "x")) > scheme@(guile-user)> (eq? a b) > $10 =3D #f > scheme@(guile-user)> (equal? a b) > $11 =3D #f And it would be pretty horrible if they were, in my book. > Thus we could go with the patch below, though I doubt it would make a > measurable difference (and it actually adds tests for other cases). It made a considerable measurable difference in LilyPond where it slowed down the operation of assoc when used for symbol lookup (while assoc has a short-circuit path to assq for SCM_IMP (key) that happens to have the same problem of not being effective for symbols). It took some debugging to figure out why so much time was spent in equal? . > Thoughts? > > Besides, in the common case where one is comparing against a symbol > literal, the question is moot: > > scheme@(guile-user)> ,optimize (equal? 'x s) > $14 =3D (eq? 'x s) That is really quite irrelevant since the problem becomes visible when a large number of comparisons in a row is done and if you were only looking for a single constant key among a large set, you'd hardly have a single constant key your code path would be looking for among that large set. > Ludo=E2=80=99. > > diff --git a/libguile/eq.c b/libguile/eq.c > index 627d6f09b..16c5bfb3f 100644 > --- a/libguile/eq.c > +++ b/libguile/eq.c > @@ -303,6 +303,8 @@ scm_equal_p (SCM x, SCM y) > return SCM_BOOL_F; > if (SCM_IMP (y)) > return SCM_BOOL_F; > + if (scm_is_symbol (x) || scm_is_symbol (y)) > + return SCM_BOOL_F; > if (scm_is_pair (x) && scm_is_pair (y)) > { > if (scm_is_false (scm_equal_p (SCM_CAR (x), SCM_CAR (y)))) > Yes, that looks reasonable. scm_is_symbol checks some tag subset that the code for equal_p later looks at closer as well: if you worry about the extra cost of the scm_is_symbol check, one could try folding the symbol check into that later code passage, which would slow down the symbol check and effect the more costly fallbacks less. But since those fallbacks _are_ more costly, I doubt it would be worth the trouble. --=20 David Kastrup