From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.devel Subject: Re: Overlays as an AA-tree Date: Sun, 19 Feb 2017 23:39:41 +0100 Message-ID: <877f4lls9e.fsf@hochschule-trier.de> References: <87d1jylv43.fsf@fastmail.com> <87fujv64mn.fsf@hochschule-trier.de> <87fujvpkzc.fsf@fastmail.com> <87vasr5tqd.fsf@hochschule-trier.de> <87d1ex4kon.fsf@hochschule-trier.de> <87d1evod6x.fsf@fastmail.com> <877f53ftab.fsf@hochschule-trier.de> <878tpiqiuc.fsf@hochschule-trier.de> <87shnppspb.fsf@hochschule-trier.de> <87o9yc9v30.fsf@hochschule-trier.de> <87a89vaes3.fsf@hochschule-trier.de> <87efz7n0g5.fsf@fastmail.com> <877f4uah6i.fsf@hochschule-trier.de> <83k28u1uyz.fsf@gnu.org> <871suxs9ad.fsf@hochschule-trier.de> <837f4pxpdc.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1487544014 6212 195.159.176.226 (19 Feb 2017 22:40:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Feb 2017 22:40:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: Joakim Jalap , Stefan Monnier , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 19 23:40:10 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cfa9J-0000q7-UG for ged-emacs-devel@m.gmane.org; Sun, 19 Feb 2017 23:40:10 +0100 Original-Received: from localhost ([::1]:35291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfa9M-0002rO-H2 for ged-emacs-devel@m.gmane.org; Sun, 19 Feb 2017 17:40:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfa9E-0002px-Dn for emacs-devel@gnu.org; Sun, 19 Feb 2017 17:40:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cfa9D-0007P1-JH for emacs-devel@gnu.org; Sun, 19 Feb 2017 17:40:04 -0500 Original-Received: from gateway-a.fh-trier.de ([143.93.54.181]:57501) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cfa97-0007Ms-QR; Sun, 19 Feb 2017 17:39:58 -0500 X-Virus-Scanned: by Amavisd-new + McAfee uvscan + ClamAV [Rechenzentrum Hochschule Trier (RZ/HT)] Original-Received: from localhost (ip5f5bdee7.dynamic.kabel-deutschland.de [95.91.222.231]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: politza) by gateway-a.fh-trier.de (Postfix) with ESMTPSA id BDBE2179AD6D; Sun, 19 Feb 2017 23:39:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha1; c=simple/simple; d=hochschule-trier.de; s=default; t=1487543981; bh=tcv61YSMw2x3yC4o0cEW2C556Uk=; h=From:To:Cc:Subject:References:Date:Message-ID:MIME-Version: Content-Type; b=Xndk4pYefAX+cUzcyBoC+lUepskjnBaxpM04YMk/MCDIFoDmcRdIdMpVo5BzWFUtj l6JjwUqFw59tkfoU/h/u/iJSg1KJ0Y2wHKw6JxPINuAJSqQp0QPfdPgl8Y+4euuSWT GZXRdTzx5p09kh95PddndfaqCt9Jc4otMAJMuNX4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 143.93.54.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:212480 Archived-At: >> From: Andreas Politz >> [...] the tree implementation is not completely free of quadratic >> worst-case performance.[...] Here is one such case were the tree is forced to search through all overlays in order to find the next change: |--------------------------| |-------------------| |-------------| B ^ E P We are looking for the next change after P, which is E. But E is the end of some overlay, and the tree knows nothing about the order of these, so it needs to consider all overlays. Here are some numbers; +------------------------+-----+------+ |2500 overlays |tree |list | +------------------------+-----+------+ |sequential/face/scroll |1.28 |1.32 | +------------------------+-----+------+ |hierarchical/face/scroll|76.59|174.64| +------------------------+-----+------+ For comparison, I added the results for the same number of overlays, but layed out in a non-overlapping, sequential fashion. I think the list performs even worse because the display engine calls overlay-recenter approx. for every line, which does nothing but traversing the after list once. Earlier I wrote to the effect, this scenario being far fetched. But there is at least one very real application coming to my mind now: A stateful folding mode using overlays to keep data about, possibly closed, folds. At the moment I can think of 4 ways out of this: 1. Use a variation of the interval tree a.) trees, the second being sorted by overlay-end. + would get rid of this altogether - more memory and code b.) Have two node types and enter every overlay twice. - probably worse than 1. in every way. c.) ??? 2. Use some heuristic cache E.g. when we are scrolling forward, a lot of re-computation of already computed end-values is performed. These could be cached in some way. + my guess is that it had the potential of improving the performance by a constant factor - won't work for random access, e.g. isearch 3. Ignore the problem I think it is a very bad idea, to replace one data-structure with bad worst-case behavior with another one. Unless we can convince ourselves that this really is no problem (*cough*). 4. Use some better data-structure We need the overlays-in function, indicating that some kind of efficient interval managing data-structure is the right approach. It just also needs to be able to answer the next-overlay-change challenge in all cases efficiently. I -ap