From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: [PATCH v2 00/16] Speeding up DEFVAR_PER_BUFFER Date: Mon, 30 Nov 2020 20:32:47 +0200 Message-ID: <835z5mk84w.fsf@gnu.org> References: <20201119153814.17541-1-sbaugh@catern.com> <837dqdxtea.fsf@gnu.org> <87a6v9jqz8.fsf@catern.com> <83y2itwbzk.fsf@gnu.org> <87ft4shxg8.fsf@catern.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29878"; mail-complaints-to="usenet@ciao.gmane.io" Cc: arnold@tdrhq.com, dgutov@yandex.ru, monnier@iro.umontreal.ca, rms@gnu.org, emacs-devel@gnu.org To: Spencer Baugh Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 30 19:37:22 2020 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 1kjo38-0007gn-FQ for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Nov 2020 19:37:22 +0100 Original-Received: from localhost ([::1]:51172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kjo37-0002Mh-H7 for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Nov 2020 13:37:21 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kjnzA-0007a9-Pg for emacs-devel@gnu.org; Mon, 30 Nov 2020 13:33:16 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:34166) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kjnz9-0003Bc-Nj; Mon, 30 Nov 2020 13:33:15 -0500 Original-Received: from [176.228.60.248] (port=3152 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kjnyp-0005OQ-Je; Mon, 30 Nov 2020 13:32:58 -0500 In-Reply-To: <87ft4shxg8.fsf@catern.com> (message from Spencer Baugh on Sun, 29 Nov 2020 12:41:59 -0500) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:260090 Archived-At: > From: Spencer Baugh > Cc: emacs-devel@gnu.org, arnold@tdrhq.com, monnier@iro.umontreal.ca, > dgutov@yandex.ru, rms@gnu.org > Date: Sun, 29 Nov 2020 12:41:59 -0500 > > > Thanks, but I would also like to hear more about patches 3 to 14, and > > how they fit into the overall idea of the speedup change. Could you > > please elaborate on that? I'm not an expert on this stuff, and I'd > > like to understand the idea better, so that I could assess each part > > in the context of its place in the overall scheme of this changeset. > > I'm sure others could also benefit from hearing more details. > > Sure, here is some overview of the change. > > === Background on DEFVAR_PER_BUFFER variables === Thank you very much for this detailed description, it makes the idea of the changes very clear. I started reviewing the patches again with this in mind, but ran out of time for today. I will try very hard to respond by tomorrow, sorry about the delay. A couple of general comments/questions, though: > === New implementation === > > In the new implementation, the BVAR macro actually does some work. > Simplifying a bit: > > #define BVAR(buf, field) EQ ((buf)->field, Qunbound) ? buffer_defaults.field : (buf)->field > > We now use Qunbound as a sentinel to tell us whether the buffer has a > buffer-local binding for this field or not. If the field contains > Qunbound, we should use the default value out of buffer_defaults; if > not, there's a buffer-local binding, and we should use the per-buffer > value. > > We no longer need to iterate over all buffers whenever we change the > default value. So setting the default value is now fast. But OTOH, referencing buffer-local values through BVAR is now slower, about twice slower, I guess? For example, the display code has 90 uses of BVAR, and they will now be slower. I wonder what that means for us: we are making let-binding of local variables much faster, but "punish" the code that just accesses these variables in our inner loops. > We could do a mass change to all the uses of BVAR, so that accesses to > non-DEFVAR_PER_BUFFER fields and permanent-buffer-local > DEFVAR_PER_BUFFER fields don't go through the conditional. But the > additional check adds minimal overhead anyway; it will be easily > branch-predicted by modern CPUs. I don't think I understand the last part: how can branch-prediction help here, when which variables do have local bindings and which don't is not known in advance and can change a lot during a session. What am I missing here? > Get rid of buffer_permanent_local_flags array > > This removes some usage of the buffer_local_flags indices in favor of a > simpler special case for the two pseudo-permanent-local variables it > applied to. Does this mean we will no longer be able to mark built-in variables as permanent-buffer-local? If so, why would we want to lose this capability? Thanks again for working on this, and I hope to complete the review by tomorrow.