From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58158: 29.0.50; [overlay] Interval tree iteration considered harmful Date: Thu, 29 Sep 2022 09:10:19 -0400 Message-ID: References: <83h70qhez0.fsf@gnu.org> <83edvuhaby.fsf@gnu.org> <831qruh67o.fsf@gnu.org> <83y1u2foli.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16964"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Gerd =?UTF-8?Q?M=C3=B6llmann?= , 58158@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 29 17:13:24 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 1odvE3-0004Dr-T7 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Sep 2022 17:13:24 +0200 Original-Received: from localhost ([::1]:57814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odvE2-0003cE-Qr for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Sep 2022 11:13:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odtJe-00081j-4b for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 09:11:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odtJd-0000sf-Ow for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 09:11:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1odtJd-0004NL-HL for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 09:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Sep 2022 13:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58158 X-GNU-PR-Package: emacs Original-Received: via spool by 58158-submit@debbugs.gnu.org id=B58158.166445703016768 (code B ref 58158); Thu, 29 Sep 2022 13:11:01 +0000 Original-Received: (at 58158) by debbugs.gnu.org; 29 Sep 2022 13:10:30 +0000 Original-Received: from localhost ([127.0.0.1]:36600 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odtJ8-0004MO-0C for submit@debbugs.gnu.org; Thu, 29 Sep 2022 09:10:30 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:37600) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odtJ5-0004M2-Og for 58158@debbugs.gnu.org; Thu, 29 Sep 2022 09:10:28 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 57B94100136; Thu, 29 Sep 2022 09:10:22 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id DA24E1000FC; Thu, 29 Sep 2022 09:10:20 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1664457020; bh=308FgYlwpV+x9hQ1L8VVgbieCZ5EBNAD9x+EcOBhPBk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=EPCnRC2q6k0wxmdoVW7ZODbeospHvVFb2hQWMsqGIxt0aKcbZfiP3NRGybY35gIFn ttuuyvT5q0kIrUicyLe4aWVbI1z3RvJPLTw/z1EtJhWKmctvyYjrr9Irl2ObE09xNe Pdw/9aBpMOni+KV/cou+RlK5FgsBO/AV3NmFeOh7boUtlbb5Lniv0Uf7G8q4/7d5Zn 2hKyzYczUs1Kx7jVaMA17OVIXbS5sLEXi2YaLCV8SxxNSeKKS5j41w8gOTrghTM38p 76UVOCaFltlkFrIVBI1GbDWkqzMaWi9Tu3IReWviwLJfkksrf9D95Zj+yvkuAyHx5T rIVjTR5QmfAuA== Original-Received: from pastel (65-110-220-202.cpe.pppoe.ca [65.110.220.202]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A698112047D; Thu, 29 Sep 2022 09:10:20 -0400 (EDT) In-Reply-To: <83y1u2foli.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 29 Sep 2022 13:43:05 +0300") 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:243904 Archived-At: > I may be missing something, but it looks like the sole purpose of the > iter_start/iter_finish dance is to ensure only one iteration per tree > is running at any given time, and that's because the iteration uses > some state variable(s) of which there's only one instance per tree. > > Stefan, am I missing something? One reason is that traversing a binary tree usually requires something like recursion, but that wouldn't fit very conveniently with the current code (nor with C in general since you can't make a local recursive closure which accesses local variables from the surrounding function). Another is the need to update the begin/end fields (these need updating because of insertions/deletions but they're updated lazily while traversing the tree to avoid an O(N) complexity during the insertions/deletions). Hiding that behind 'some kind of "next node" function keeps the code more readable. But yes, the current restriction to have a single iteration at a time is a bit of a problem, especially because it's very "global". I added a comment yesterday describing how we could make it non-global (hence getting rid of the `visited` flag in the nodes). For now, I pushed a simple fix to traverse the tree "by hand" in the GC rather than via the iterator. Stefan