From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Overlays as an AA-tree Date: Tue, 21 Feb 2017 14:18:44 -0500 Message-ID: References: <87d1jylv43.fsf@fastmail.com> <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> <877f4lls9e.fsf@hochschule-trier.de> <838tp0q3k8.fsf@gnu.org> <87vas4owus.fsf@luca> <87r32rpfhv.fsf@luca> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1487704802 22509 195.159.176.226 (21 Feb 2017 19:20:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 21 Feb 2017 19:20:02 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 21 20:19:57 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 1cgFye-0005Et-6f for ged-emacs-devel@m.gmane.org; Tue, 21 Feb 2017 20:19:56 +0100 Original-Received: from localhost ([::1]:48036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgFyi-0006sj-6W for ged-emacs-devel@m.gmane.org; Tue, 21 Feb 2017 14:20:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgFxr-0006qw-8I for emacs-devel@gnu.org; Tue, 21 Feb 2017 14:19:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgFxn-0004RX-8u for emacs-devel@gnu.org; Tue, 21 Feb 2017 14:19:07 -0500 Original-Received: from [195.159.176.226] (port=51231 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cgFxn-0004Qu-1g for emacs-devel@gnu.org; Tue, 21 Feb 2017 14:19:03 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cgFxb-0000Ed-EV for emacs-devel@gnu.org; Tue, 21 Feb 2017 20:18:51 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 78 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:boc1TFqIZ/zO1KffRYqLCr3BCCw= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:212531 Archived-At: > /* master */ > struct Lisp_Overlay > { > ENUM_BF (Lisp_Misc_Type) type : 16; > bool_bf gcmarkbit : 1; > unsigned spacer : 15; > struct Lisp_Overlay *next; > Lisp_Object start; /* -> 40 bytes */ > Lisp_Object end; /* -> 40 bytes */ > Lisp_Object plist; /* -> 40 bytes */ > }; /* 40 bytes */ > /* Total: 40 + 3*40 = 160 */ Hmm... I don't know how you're counting either ;-) the type+gcmarkbit+spacer bit fields sum up to 32bits (let's round that to a "word"). Then we have 4 fields that hold a "word" (Lisp_Object is basically an integer), for a total of 5 words. On 32bit systems, alloc.c rounds it up further to 6 words or 24B (because Lisp_Objects have to be aligned on a multiple of 8B). > /* noverlay */ > struct Lisp_Overlay > { > ENUM_BF (Lisp_Misc_Type) type : 16; > bool_bf gcmarkbit : 1; > unsigned spacer : 15; > Lisp_Object plist; /* -> 40 bytes */ > struct buffer *buffer; > struct interval_node *interval; > }; /* 32 bytes */ So that's 4 words (one less than before). > struct interval_node /* layout tweaked */ > { > struct interval_node *parent; > struct interval_node *left; > struct interval_node *right; > ptrdiff_t begin; /* The beginning of this interval. */ > ptrdiff_t end; /* The end of the interval. */ > ptrdiff_t limit; /* The maximum end in this subtree. */ > ptrdiff_t offset; /* The amount of shift to apply to this subtree. */ > uintmax_t otick; /* offset modified tick */ > Lisp_Object data; /* Exclusively used by the client. */ > bool_bf visited : 1; /* For traversal via generator. */ > bool_bf rear_advance : 1; /* Same as for marker and overlays. */ > bool_bf front_advance : 1; /* Same as for marker and overlays. */ > enum { ITREE_RED, ITREE_BLACK } color : 1; > }; /* 80 bytes */ > /* Total: 32 + 40 + 80 = 152 */ Here I count 9 words plus some bit fields (i.e. 10 words). I assume there's one "struct interval_node" per overlay object, so every overlay object uses 14 words (plus 2 because all Lisp_Misc end up using 6 words anyway) which is indeed less than the current setup. Is there a reason why "struct Lisp_Overlay" and "struct interval_node" are separate? IOW could we have a single struct with all the fields together (as a Lisp_Vectorlike rather than a Lisp_Misc)? If so, we could bring this down to 12 words plus the Lisp_Vectorlike header, i.e. 14 words. [ Of course, we could probably squeeze it a bit further if we really care, e.g. merge the `parent' and `buffer' fields, at the cost of walking up the tree when we need to find the overlay's buffer. But I doubt it's worthwhile. ] That means an overlay takes up about twice the size of a marker. Should we then (re)implement markers as degenerate overlays? [it's not as simple as it sounds: contrary to overlays markers can be GC'd if not referenced, so we'd need to add support for "weakly referenced overlays". Furthermore markers are used to speed up byte<->char conversions, so we'd need to replace that code accordingly. ] Stefan