all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: JD Smith <jdtsmith@gmail.com>
Cc: emacs-devel@gnu.org, casouri@gmail.com
Subject: Re: Mitigating the long-lines penalty in vundo
Date: Sun, 17 Dec 2023 21:43:46 +0200	[thread overview]
Message-ID: <8334w0k425.fsf@gnu.org> (raw)
In-Reply-To: <722361DD-7F6C-42EC-921A-348285895242@gmail.com> (message from JD Smith on Sun, 17 Dec 2023 14:26:23 -0500)

> From: JD Smith <jdtsmith@gmail.com>
> Date: Sun, 17 Dec 2023 14:26:23 -0500
> Cc: emacs-devel@gnu.org,
>  casouri@gmail.com
> 
> > Lisp programs are not supposed to need frequent column calculations,
> > certainly not several times on the same line.
> 
> Maybe then it’s worth a word of warning in the current-column docs mentioning this in the context of faces, unicode, and long-line performance?

I'm not sure.  It was never a problem until now.  Warning against very
rare issues could have negative effects of its own.

> >> * current-column is quite slow counting unicode characters: about 21x slower than the ascii
> >> equivalents.  Perhaps this is because unicode chars can have non-standard widths, so emacs
> >> needs to do some additional checks?
> > 
> > No.  I can understand why non-ASCII characters are somewhat slower,
> > since each one of them is several bytes, not just one, and we convert
> > the multibyte representation into a codepoint on the fly.  But 21-fold
> > slowdown sounds excessive.
> 
> Results may vary by system/font I suppose; perhaps others could run the simple test in my last message (no non-default packages required) and report back what slowdown factor they get.

current-column does not depend on fonts and knows nothing about fonts.
The canonical width of every character is stored in a char-table that
is indexed only by the character's codepoint, and is independent of
any real font metrics.

> > There's one more factor to consider here: current-column always starts
> > from the beginning of the line.  If vundo needs to call current-column
> > many times on the same line, it loses because it each time starts from
> > BOL, in effect throwing away the results of the previous calculation.
> > This wastes CPU cycles.  It might be better to use sum char-width
> > values of individual characters instead.
> 
> Definitely; it’s clear how repetitive/wasteful this is.  I wonder, similar to line-numbers, could we cache current-column at various points along a line and apply a delta?  I.e. for computing line numbers differentially we have
> 
> (count-lines start end) 
> 
> which linum and others use to good effect.  Is there a similar
> 
> (count-columns start end)?  

This is impossible in general (think TABs).  What we can do is provide
something like

  (count-columns startpos startcol endpos)

IOW, we need to tell the function what is the column at STARTPOS.  And
then there will be problems if STARTPOS is "covered" by an overlay or
a display property...



      reply	other threads:[~2023-12-17 19:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-16 16:19 Mitigating the long-lines penalty in vundo JD Smith
2023-12-16 16:45 ` Eli Zaretskii
2023-12-16 18:54   ` JD Smith
2023-12-16 19:13     ` Eli Zaretskii
2023-12-16 20:32       ` Stephen Berman
2023-12-16 22:00       ` JD Smith
2023-12-17  7:28         ` Eli Zaretskii
2023-12-17 17:49           ` JD Smith
2023-12-17 18:07             ` Eli Zaretskii
2023-12-17 19:26               ` JD Smith
2023-12-17 19:43                 ` Eli Zaretskii [this message]

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=8334w0k425.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=jdtsmith@gmail.com \
    /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.