unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Spencer Baugh <sbaugh@catern.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: [PATCH 0/7] Cleanups and tests for DEFVAR_PER_BUFFER variables
Date: Thu, 01 Apr 2021 14:13:50 -0400	[thread overview]
Message-ID: <87a6qhyish.fsf@catern.com> (raw)
In-Reply-To: <E1lOwBl-0000ZJ-Eo@fencepost.gnu.org>

Eli Zaretskii <eliz@gnu.org> writes:
> I'd prefer to pick up where we left off back then.  The main issue
> left unresolved in the past discussion was the potential slowdown of
> simple accesses to buffer-local vars due to your proposal.  Can we
> please have benchmarks for that, so we could decide whether the
> tradeoff is worth it?  It's quite possible that the performance
> aspects could affect the code changes, so even uncontroversial
> cleanups should perhaps wait until we have figured out the more
> important aspects of these changesets.

OK, I ran some basic benchmarking. Specifically, I ran

(defun shr-benchmark ()
  (let ((gc-cons-threshold 800000000))
    (message "shr-benchmark result: %s"
             (benchmark-run 100
               (dolist (file (directory-files (ert-resource-directory) nil "\\.html\\'"))
                 (shr-test (replace-regexp-in-string "\\.html\\'" "" file)))))))

out of shr-tests.el.

My results (each from running emacs -f shr-benchmark 10 times and
discarding the first 2 results):

| Unmodified Emacs                  | 2.265s |
| With original changes             | 2.295s |
| Avoid unnecessary Qunbound checks | 2.266s |

My original changes imposed about a 1-2% slowdown on an unmodified
Emacs.  That's unacceptable, so I made a further change to only check
Qunbound for vars where it was actually necessary.  That makes the
performance comparable to an unmodified Emacs, so I think in terms of
performance that should put this in a good state.

To statically avoid checking Qunbound for vars where it's not necessary,
we need to use separate syntax for accessing BVARs that have defaults
and BVARs that don't have defaults. Only BVARs that have defaults need a
Qunbound check.  (We could use the same syntax for both, but it would
require X macros which Eli disliked earlier)

I see three general options for the syntax for accessing each kind of
var:

|            | Var with default             | Var without default      |
|------------+------------------------------+--------------------------|
| Status quo | BVAR (buf, field)            | BVAR (buf, field)        |
| Option 1   | BVAR (buf, field)            | buf->field               |
| Option 2   | BVAR (buf, field)            | BVAR_DIRECT (buf, field) |
| Option 3   | BVAR_OR_DEFAULT (buf, field) | BVAR (buf, field)        |

(The specific names for BVAR_DIRECT or BVAR_OR_DEFAULT don't matter,
we can make them shorter if we want).

What do people prefer?

I went with option 3 for the large refactoring, but if it's OK in
terms of coding style I think option 1 is nicer.

In any case we should ensure that we can't accidentally, for example,
use BVAR_DIRECT on a field that actually has a default.  This should
be easy enough by just naming the fields slightly differently.

I'll post my updated patches after I know which syntax people would
prefer. (The change compared to the earlier patches is pretty small,
besides adjusting all the BVAR usages to use the new syntax)



  parent reply	other threads:[~2021-04-01 18:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24  3:11 [PATCH 0/7] Cleanups and tests for DEFVAR_PER_BUFFER variables Spencer Baugh
2021-03-24  3:11 ` [PATCH 1/7] Add a test for let-binding unwinding Spencer Baugh
2021-03-24  3:11 ` [PATCH 2/7] Assert not local-variable-p after setq in let_default binding Spencer Baugh
2021-03-24  3:11 ` [PATCH 3/7] Stop checking the constant default for enable_multibyte_characters Spencer Baugh
2021-03-24  3:11 ` [PATCH 4/7] Take buffer field name in DEFVAR_PER_BUFFER Spencer Baugh
2021-03-24  3:11 ` [PATCH 5/7] Combine unnecessarily separate loops in buffer.c Spencer Baugh
2021-03-24  3:11 ` [PATCH 6/7] Assert that PER_BUFFER_IDX for Lisp variables is not 0 Spencer Baugh
2021-03-24  3:11 ` [PATCH 7/7] Remove unnecessary Qunbound check Spencer Baugh
2021-03-25 16:46   ` Stefan Monnier
2021-03-24  5:36 ` [PATCH 0/7] Cleanups and tests for DEFVAR_PER_BUFFER variables Eli Zaretskii
2021-03-25 16:48   ` Stefan Monnier
2021-03-25 17:00     ` Eli Zaretskii
2021-04-01 18:13   ` Spencer Baugh [this message]
2021-04-01 18:51     ` Eli Zaretskii
2021-04-03 20:53       ` Spencer Baugh
2021-04-04  7:15         ` Eli Zaretskii
2021-04-01 21:42     ` Stefan Monnier
2021-04-01 23:39       ` Spencer Baugh
2021-04-02  2:55         ` Stefan Monnier
2021-04-02  5:36       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6qhyish.fsf@catern.com \
    --to=sbaugh@catern.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).