From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Armstrong Newsgroups: gmane.emacs.devel Subject: Re: noverlay branch Date: Mon, 26 Sep 2022 22:12:44 -0700 Message-ID: <87bkr1e6yb.fsf@rfc20.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37510"; mail-complaints-to="usenet@ciao.gmane.io" To: Stefan Monnier , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 27 07:14:42 2022 Return-path: Envelope-to: ged-emacs-devel@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 1od2va-0009Yl-Li for ged-emacs-devel@m.gmane-mx.org; Tue, 27 Sep 2022 07:14:42 +0200 Original-Received: from localhost ([::1]:58142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1od2vY-0007Lb-PN for ged-emacs-devel@m.gmane-mx.org; Tue, 27 Sep 2022 01:14:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od2ts-0006do-Eh for emacs-devel@gnu.org; Tue, 27 Sep 2022 01:12:56 -0400 Original-Received: from relay12.mail.gandi.net ([2001:4b98:dc4:8::232]:54559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od2tp-0007cm-Fp for emacs-devel@gnu.org; Tue, 27 Sep 2022 01:12:56 -0400 Original-Received: (Authenticated sender: matt@rfc20.org) by mail.gandi.net (Postfix) with ESMTPSA id 6C1E4200002; Tue, 27 Sep 2022 05:12:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rfc20.org; s=gm1; t=1664255568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=U+IOSXzE0UTVkHEwpMQrUVweEinONLxT++yDEXjIdMI=; b=aYAWGiD/BA4tu/xdcNbP5yFj+4HdSHUjEkPg/unIt1Pu6MIesBIX0Y3FNA7d6HtalIH6mW alijQs8iD9ngvVOjgQy9DZOn1TtZ59U+qPYShw0RaZeYfDGvDIQhnqUlyLVAWbje3Sd9XA ASZN/WMhzIqnmJvoHLo5Y4PXiQK/rEhHhw5yZs2kM/cqCGKwrxVgQsTa+GxHn0LQXqukUm cV7zbhG/tmz19a7HzRZAxdbFTEHJhpKwI6BuJ545dKk0nQrSf9sofKSZMGlgn0mc/WYAVP 6hVCIzH2SzgebZU2+BjFEWNhjlBXlOqdK5h5HmjocD8xDJsA2kvPieAxowQLrg== Original-Received: from matt by naz with local (Exim 4.96) (envelope-from ) id 1od2tg-0002Jf-0f; Mon, 26 Sep 2022 22:12:44 -0700 In-Reply-To: Received-SPF: pass client-ip=2001:4b98:dc4:8::232; envelope-from=matt@rfc20.org; helo=relay12.mail.gandi.net 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:296315 Archived-At: Stefan Monnier writes: > I just updated the noverlay branch to the code in `master` (most of it > was mechanical except for the fact that since the last commit on that > branch we have gotten rid of Lisp_Misc and we moved to pdumper). This is pretty exciting! I've been looking at the noverlay branch as well in some detail, but only as a background task, over the past year. I haven't considered the branch ready for merge because I saw some areas where I think the implementation should improve. But, working code is a compelling thing. If noverlay is ready to merge I'd suggest doing it. Code can improve later, as and if needed. I was planning to takle these problems before proposing a merge: 1) Improve the worst case run time of `previous-overlay-change' from O(n) to O(log N). The noverlay branch uses an O(N) algorithm, though it is difficult to spot. Since the point of using a tree is O(log N) algorithms, and O(n) algorithms can easily become exponential algorithms when composed in higher level loops (the problem overlays sees today), this strikes me as important. 2) Look at reducing the number of malloc'd overlay blocks in half by expressing the tree intrusively (the same way the overlay list is today). I don't see a lot of value in itree.h/c abstracting away the interval logic from the overlay object itself. 3) Improve quality of comments in the new code. Personally, I find the algorithms quite subtle and quite a bit more complex than what you find on, say, https://en.wikipedia.org/wiki/Interval_tree or the Cormen et al. Introduction to Algorithms Book. I think I pieced most of it together but it took a lot of effort. At top of mind is looking at the interval_node.visited flag and figure out how that flag is used, then describe the algorithm in detail. It isn't clear to me how that flag gets set/cleared. Best case: doing so proves me wrong on point (1). And lower priority: 4) The overlay `front-advance' and `rear-advance' booleans are conceptually part of the overlay's BEG and END positions, except that this is ignored everhwhere except insertion. Upon insertion at any given POS the overlays are according to *both* their BEG or END positions and the *-advance booleans. Yet, this is not used when ordering overlays in the tree. Doing that may bring an opportunity to simplify code or make it more efficient. (Side note: there *may* also be a way to encode the *-advance flags implicitly in the beg/end fields positions if a way can be found to "steal" the free bit in the currently signed ptrdiff_t fields, effectively causing the *-advance flags to count as this extra "half" position for the purpose of insertion). 5) Look at using an augmented B-tree of overlays instead of a binary tree. B-trees are quite often faster than binary trees (at least on hardware made over the past few decades), so there is that enticing proposition. They're also typically not harder to implement, either, requiring no "rotations" nor convluted deletion logic. An *augmented* B-tree may also allow for simplification of the relative vs. absolute offsets in the tree. The noverlay branch currently handles this by treating the absolute offsets as cached values, "dirtying" them whenever any mutation occurs in the tree, and recomputing absolute offsets on demand. If augmented in the right way a B-tree might be shallow enough in practice that recomputation on demand is always fast enough, so the the invalidation/caching approach (as well as the memory used to track it) can go away. (wild idea)