From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: Guile's time execution issues Date: Fri, 08 May 2020 13:31:44 +0200 Message-ID: <29b88b88-00c4-478e-8587-7a6e2d7a8e39@www.fastmail.com> References: <87d07u182a.fsf@gnu.org> <87a72q77gr.fsf@gnu.org> <87r1w0rqhc.fsf@gnu.org> <874ksvqx7k.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="7589"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.3.0-dev0-413-g750b809-fmstable-20200507v1 Cc: guile-user , guile-devel To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri May 08 13:32:26 2020 Return-path: Envelope-to: guile-user@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 1jX1Ev-0001qt-Q8 for guile-user@m.gmane-mx.org; Fri, 08 May 2020 13:32:26 +0200 Original-Received: from localhost ([::1]:48122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX1Eu-0003eg-Nj for guile-user@m.gmane-mx.org; Fri, 08 May 2020 07:32:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX1Eh-0003dC-2K; Fri, 08 May 2020 07:32:11 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:40051) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX1Ef-0005nZ-Kl; Fri, 08 May 2020 07:32:10 -0400 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id EC2FD5C030F; Fri, 8 May 2020 07:32:06 -0400 (EDT) Original-Received: from imap1 ([10.202.2.51]) by compute7.internal (MEProxy); Fri, 08 May 2020 07:32:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=veryfast.biz; h= mime-version:message-id:in-reply-to:references:date:from:to:cc :subject:content-type:content-transfer-encoding; s=fm2; bh=UNG9W H0TgE7OKLCdUg3PgPYgyeR+kelqMBazmRpqV5Y=; b=EkwtkPhS17rVkwXaOsNMH mnaRxh7KYXXRhct8+oqDbn4D9ihLVt612dXPQIqgwowcjnRZDuGCkxVTz1PzHPxc FA/R+GAwY+Axs/esyRNiNxNR7z29tqN5CqzH4uWx/AmUkS7KqitKFsidtmpBz7dO uwN6X94zn+CJB8l+m3c5SrZ1bz8WJaedp6ulyy/silg+uSXvYw2jHoSiLM4X9uyf XF0D7Xr1VE/60p6DUvhdYvz0OjFAB9VsdINQJs5kBg1id2qImqUk7kEHFiDrvhut ldDKRyLf7VWW7pYV06TNcTxPJAlqcEJ/hHzM1DL6wU2SQovobglLsfW8KR+EK/n7 Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=UNG9WH0TgE7OKLCdUg3PgPYgyeR+kelqMBazmRpqV 5Y=; b=Q2nBcpAxxQHCwqdfBsBZh8c1IKp/qkKykQB3Tr6PuO3MPCEiAo3ufq+wr 1erOHAsSLja6Te3xqvK8QAYBI8Pv90bUBQZIGd1PJtISJlfX3ExiFyjw8fKyVDQ8 /FM306YIW+h31iKkZ+sHJc8V/EgRD4o9JUNgMcHquJIRFJHj9ZfDIzGcCAmYoEvL YnjZ0qVANpE3TUSlLkHGsM5Nn88rqVplmfJqzFASIrDnXqGVM9LEvMt00vAIUfSz IEVUDy60+uIUtbULs7QWWQpjklZyULzto5ObFgYMYv0Dg2cc8Tl+n3juTVpp50/L mN5rBxvyTTr5Z8PdQTvkgTyvmSRQQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrkedvgdegtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepnfhinhhu shgpuehjnphrnhhsthgrmhcuoehlihhnuhhsrdgsjhhorhhnshhtrghmsehvvghrhihfrg hsthdrsghiiieqnecuggftrfgrthhtvghrnhepfedvuefhjedtfeffkeeuuddtjeehhefg hfffvdejleeikeelffejudfgvddvffdvnecuffhomhgrihhnpehgihhthhhusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlihhn uhhsrdgsjhhorhhnshhtrghmsehvvghrhihfrghsthdrsghiii X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6847BC200A4; Fri, 8 May 2020 07:32:06 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: Received-SPF: pass client-ip=66.111.4.25; envelope-from=linus.bjornstam@veryfast.biz; helo=out1-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/08 07:32:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16439 gmane.lisp.guile.devel:20513 Archived-At: Another option would be to just overload equal? in match.scm to transfor= m into eqv? when there are char literals or numbers, eq? on symbols, boo= leans, the empty list and keywords and (@@ (guile) equal?) for everythi= ng else. Considering that it in this case contributed a 25% overhead to code that= was performance critical I think it would be a pretty valid thing to do= . If you, ludo, an Andy thinks that would be a good idea I can make such= a patch for match.scm. That would have the benefit of not changing the = upstream code (which is (include ...)d in match.scm), nor fiddling aroun= d with guile optimisations. --=20 Linus Bj=C3=B6rnstam On Mon, 4 May 2020, at 22:50, Linus Bj=C3=B6rnstam wrote: > You didn't see my other reply. The matching code isn't suboptimal. The= =20 > equality predicate is The problem is that match compares using equal?= =20 > even for literal chars (where eqv? is a lot faster). It would be a=20 > rather trivial optimization to do, either to match.scm (meaning:=20 > breaking with upstream and use syntax-case) or to the guile compiler i= n=20 > general (changing equal? to eqv, when there are character literals),=20= > which seems ok-ish for this use-case but at very little benefit in=20 > general. >=20 > A long-term goal of mine is to write a pattern matcher with the=20 > optimisations that the racket matcher does (among other things: some=20= > serious list matching reordering!). That is a daunting task though. >=20 > --=20 > Linus Bj=C3=B6rnstam >=20 > On Mon, 4 May 2020, at 22:09, Ludovic Court=C3=A8s wrote: > > Hi, > >=20 > > Linus Bj=C3=B6rnstam skribis: > >=20 > > > On Mon, 4 May 2020, at 11:36, Ludovic Court=C3=A8s wrote: > > > =20 > > >> > One thing I found is that `match` is slow. The code looked nice= r but had to change it back to lets and conds as the performance > > >> > increase was ~2 seconds. > > >>=20 > > >> Oh, in which case exactly? And are you sure your hand-written co= de is > > >> equivalent to the =E2=80=98match=E2=80=99 code (it=E2=80=99s comm= on for hand-written code to be > > >> more lax than =E2=80=98match=E2=80=99)? > > >>=20 > > >> One thing to pay attention to is the use of =E2=80=98list?=E2=80=99= , which is O(N), and > > >> is implied by ellipses in =E2=80=98match=E2=80=99. If you want t= o use =E2=80=98match=E2=80=99 in a way > > >> that avoids =E2=80=98list?=E2=80=99, write patterns such as (a . = b) instead of (a b ...). > > >> It doesn=E2=80=99t have the same meaning, but often the end resul= t is the same, > > >> for instance because you=E2=80=99ll later match on =E2=80=98b=E2=80= =99 anyway. > > >>=20 > > >> (I wish we can one day have a proper list type disjoint from pair= s=E2=80=A6) > > > > > > The change is here: he is only matching against chars and predicat= es: https://github.com/aconchillo/guile-json/commit/ad4b06d86e4822466983= d00f55474c8f664b538d > >=20 > > It would be nice if you could pinpoint which one of these changes ca= uses > > a difference, because: > >=20 > > --8<---------------cut here---------------start------------->8--- > > scheme@(guile-user)> ,optimize (match (peek-char port) ((? eof-objec= t?)=20 > > x) ((? whitespace?) w) (_ e)) > > $84 =3D (let ((v (peek-char port))) > > (cond ((eof-object? v) x) > > ((whitespace? v) w) > > (else e))) > > --8<---------------cut here---------------end--------------->8--- > >=20 > > What might make a difference is the code bloat when using =E2=80=98o= r=E2=80=99: > >=20 > > --8<---------------cut here---------------start------------->8--- > > scheme@(guile-user)> ,optimize (match (peek-char port) ((or #\a #\b = #\c #\d) x)) > > $86 =3D (let ((v (peek-char port))) > > (cond ((equal? v #\a) x) > > ((equal? v #\b) x) > > ((equal? v #\c) x) > > ((equal? v #\d) x) > > (else > > ((@@ (ice-9 match) error) > > 'match > > "no matching pattern" > > v) > > #f))) > > --8<---------------cut here---------------end--------------->8--- > >=20 > > but even that sounds unlikely. > >=20 > > You=E2=80=99re compiling with -O2, right? > >=20 > > Thanks, > > Ludo=E2=80=99. > > >=20 >