Subject: bug#48264: 28.0.50; Changing the default for DEFVAR_PER_BUFFER variables takes O(#buffers) time

From: Spencer Baugh <[email-masked]>
Date: Thu, 06 May 2021 16:24:30 -0400

When changing the default for a Lisp variable defined in the C source
with the DEFVAR_PER_BUFFER macro, whether by let or by set-default, it
takes time proportional to the number of currently live buffers.

Note, DEFVAR_PER_BUFFER variables are stored as Lisp_Object fields in
struct buffer.

The cause of the pathological performance is that setting a default for
a DEFVAR_PER_BUFFER variable iterates over every struct buffer (that
doesn't already have a binding) to set the field corresponding to the
variable.

This is because accessing a DEFVAR_PER_BUFFER variable is done purely by
looking at the current buffer, even if the buffer doesn't have a local
binding for the variable.

This issue was previously reported in bug#41029 and noticed as part of
several other bugs.

I have a patch series which fixes this issue by making DEFVAR_PER_BUFFER
variable accesses fall back to the default if there's no local binding
for the variable, which I'll send shortly as a followup.