all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Phil Sainty <psainty@orcon.net.nz>,
	Stefan Kangas <stefan@marxist.se>,
	58513@debbugs.gnu.org
Subject: bug#58513: describe-function should say that defconst variables are constant
Date: Fri, 14 Oct 2022 12:44:01 -0400	[thread overview]
Message-ID: <jwv4jw6fjr5.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87sfjq7a91.fsf@gnus.org> (Lars Ingebrigtsen's message of "Fri, 14 Oct 2022 16:25:30 +0200")

Lars Ingebrigtsen [2022-10-14 16:25:30] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> FWIW, my own local Emacs has `defconst` create actually
>> constant variables by adding a `SYMBOL_DEFCONST` to `enum
>> symbol_trapped_write`.  Admittedly I didn't make them really constant:
>> I allow a subsequent `defconst` to change the value set by a previous
>> `defconst`, but `setq` signals an error just like it does if you try to
>> `setq` on `enable-multibyte-characters` or on `nil`.
>
> Hm...  do you know if there's a performance impact from doing this?

In terms of memory use, we already use 2 bits for that `enum
symbol_trapped_write`, so adding a new value doesn't cost anything
at all.

In terms of run-time, it adds a 4th branch to a few 3-branch `switch`
statements, so it can have a performance impact, most importantly in
`set_internal`, I guess, but I'd be very surprised if it's ever not lost
in the noise:

- it only affects `setq` on global/dynamic vars which should be a small
  fraction of the overall `setq` we perform nowadays.
- since that new branch always signals an error (well, in my own code,
  that is: I don't know what that branch would end up doing on `master`
  where we'd want to be more careful about backward compatibility), it's
  expected to be more-or-less never taken and even the most naive branch
  predictors should handle it "perfectly".


        Stefan






  reply	other threads:[~2022-10-14 16:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 12:04 bug#58513: describe-function should say that defconst variables are constant Stefan Kangas
2022-10-14 12:23 ` Lars Ingebrigtsen
2022-10-14 12:35   ` Phil Sainty
2022-10-14 12:40     ` Lars Ingebrigtsen
2022-10-14 13:03       ` Stefan Kangas
2022-10-14 13:07         ` Lars Ingebrigtsen
2022-10-14 13:34           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-14 14:25             ` Lars Ingebrigtsen
2022-10-14 16:44               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-10-15 10:04                 ` Lars Ingebrigtsen
2022-10-16 20:51                   ` Richard Stallman
2022-10-16 21:11                     ` Drew Adams
2022-10-17  5:41                     ` Stefan Kangas
2022-10-17 10:41                       ` Lars Ingebrigtsen
2022-10-15 12:33             ` Stefan Kangas
2022-10-15 14:11               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

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

  git send-email \
    --in-reply-to=jwv4jw6fjr5.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=58513@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=psainty@orcon.net.nz \
    --cc=stefan@marxist.se \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.