From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#52753: 29.0.50; Printing long list-like structures fails Date: Sun, 23 Jan 2022 17:28:06 +0100 Message-ID: References: <22AEBE6E-68E7-47D9-885C-AE6621AF4AEE@acm.org> <87o856b7ak.fsf@localhost> <5D2E995F-7A93-4A75-8AE9-AFCE02399D4E@acm.org> <8735le7ha7.fsf@localhost> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31989"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 52753@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 23 17:29:11 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1nBfjq-00087g-4g for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 23 Jan 2022 17:29:10 +0100 Original-Received: from localhost ([::1]:46004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nBfjp-0002ub-8C for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 23 Jan 2022 11:29:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBfji-0002uS-HT for bug-gnu-emacs@gnu.org; Sun, 23 Jan 2022 11:29:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48085) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nBfji-00054Z-6N for bug-gnu-emacs@gnu.org; Sun, 23 Jan 2022 11:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nBfji-00022r-1V for bug-gnu-emacs@gnu.org; Sun, 23 Jan 2022 11:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 23 Jan 2022 16:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52753 X-GNU-PR-Package: emacs Original-Received: via spool by 52753-submit@debbugs.gnu.org id=B52753.16429552957729 (code B ref 52753); Sun, 23 Jan 2022 16:29:01 +0000 Original-Received: (at 52753) by debbugs.gnu.org; 23 Jan 2022 16:28:15 +0000 Original-Received: from localhost ([127.0.0.1]:40988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBfix-00020a-7m for submit@debbugs.gnu.org; Sun, 23 Jan 2022 11:28:15 -0500 Original-Received: from mail72c50.megamailservers.eu ([91.136.10.82]:40486 helo=mail92c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBfiu-00020L-Eg for 52753@debbugs.gnu.org; Sun, 23 Jan 2022 11:28:13 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1642955290; bh=gvzwFvq0/7kuyu+g2n/vKwfk7dgOcGq4oHoJo6nOOc8=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=EYPHM5WADWYVB0+TmFjeyu/+E1gO4TDGIENg6uoPqDGFrRCQutNwDogeyen0Quovc gAOb3Lt1In6JTdjBNXRG9yo89r6ZhTx5bzm8du1Sw4X5fFNIrnATqhB2aZzvfYYieu 96MwQfAXqFDxNqBFV4U3kY0FZHWO5/CKXluFjKOM= Feedback-ID: mattiase@acm.or Original-Received: from smtpclient.apple (c-b952e353.032-75-73746f71.bbcust.telenor.se [83.227.82.185]) (authenticated bits=0) by mail92c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 20NGS73B001061; Sun, 23 Jan 2022 16:28:09 +0000 In-Reply-To: <8735le7ha7.fsf@localhost> X-Mailer: Apple Mail (2.3654.120.0.1.13) X-CTCH-RefID: str=0001.0A742F1C.61ED821A.0003, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-Origin-Country: SE X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:224938 Archived-At: 23 jan. 2022 kl. 13.44 skrev Ihor Radchenko : > I tried to understand the printer code, but it appears to be too = complex > for me. Maybe I am just not familiar enough with the C part of Emacs. It's complex partly because of its age, but also because we ask a lot = it. While it would be nice to extend it and the reader to handle = arbitrarily complex structures, I'm not sure your case is a motivation = strong enough since the complexity of your data structure is more = accidental than essential. > While I understand how the illustrated example is difficult for the > reader, note that recursion is _not_ in the car slot. Each list = element > is a structure like (key . forward-vector) with key being the stored > value and forward-vector storing forward references to the next > elements. Conceptually, ordinary list is just a degenerate case of = skip > list with forward-vector storing a single forward-reference to the = next > element in the list. Sorry, my mistake -- the recursion is through the stacked conses and = vectors in the cdr position, which changes absolutely nothing at all. = Your data structure is not a list in the Lisp sense, which is the only = recursion that the reader and printer can handle without consuming = stack. > Since your last message, I have dived into the more recent literature = on > data structures. That's the spirit! > It looks like skip lists are not that bad - similar to > even older AVL-tree they got updated with finger search facilities and > auto-adjustments to non-random data [1,2]. However, a systematic > comparison between AVL-trees, skip lists, and splay trees reveals that > insertion into skip lists perform up to 2x worse compared to = AVL-trees, > especially for random insertion [3]. Ref. [3] generally agrees with my > measurements. On the other hand, Ref. [3] showed that average lookup > time should be 2x faster in skip lists - very different from my > implementation. I may be doing something wrong. Emacs Lisp as an implementation environment comes with its own set of = constraints, data structures and primitives that strongly affect what = algorithms will be practical and is very different from C, say. > we have to insert a new element and shift the :begin keys of all the > elements below: >=20 > (:begin 1 "headline 1" ...) > (:begin 13 "new" ...) > (:begin 13+7 "subheadline" ...) > (:begin 28+7 "headline 2" ...) Forgive my ignorance, but wouldn't this call for some sort of interval = tree where the children's offset are relative to their parents? Then = shifting keys in an interval only requires modifying a few upper nodes. > B-trees may be an option, but I do not > see how they would be advantageous compared to AVL trees. We do > everything in memory. Locality matters in memory too! Well-implemented B-trees are usually = competitive with binary trees even in RAM. I have no idea how easy that = would be to pull off in Elisp, though. (I've rarely had good experience with splay trees but I suppose they can = be useful in the right circumstances.) > This is really counter-intuitive. I am wondering how much can be the > difference in practice. At least by orders of magnitude. Did you expect a difference in orders of magnitude? Implementation = choices do not often come that clear-cut. C primitives can often be faster than ones implemented in Lisp even if = using a less clever algorithm (for example, try comparing `memq` against = a set implemented as a balanced binary tree lookup in Lisp). We also have to contend with a rather antique garbage collector.