all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Mohammed Sadik <sadiq@sadiqpk.org>
Cc: 23327@debbugs.gnu.org
Subject: bug#23327: 25.0.92; show-trailing-whitespace uses too much cpu
Date: Thu, 21 Apr 2016 17:16:08 +0300	[thread overview]
Message-ID: <837ffr6o9j.fsf@gnu.org> (raw)
In-Reply-To: <CANHUxH1YNSv+raZB6Ctq_pMYusEcsYOpJ1FxGcect=VZfM9PDQ@mail.gmail.com> (message from Mohammed Sadik on Thu, 21 Apr 2016 11:33:55 +0530)

> Date: Thu, 21 Apr 2016 11:33:55 +0530
> From: Mohammed Sadik <sadiq@sadiqpk.org>
> 
> Enabling show-trailing-whitespace and navigating through buffer uses too
> much CPU.  An increase of about 4-6% of CPU on my 2.4 GHz Quad-core
> system.
> 
> How to reproduce:
> 
> 1. Open a large source code file (I opened cc-engine.el from Emacs source).
> 2. Enable show-trailing-whitespace (setq show-trailing-whitespace t)
> 3. Press and hold the arrow keys to navigate. See the processor usage
>    (use top/htop or similar program).
> 4. Now disable show-trailing-whitespace (setq show-trailing-whitespace
>    nil)
> 5. Repeat 3
> 
> This also happens when pressing any other key (eg:while typing).

The Emacs display engine employs several aggressive optimizations for
simple operations like cursor motion and inserting a single
character.  When you turn on show-trailing-whitespace, most of these
optimizations are disabled, so it's very small wonder that redisplay
becomes more expensive.

The reason that these optimizations are disable is this feature of
show-trailing-whitespace:

     This feature does not apply when point is at the end of the line
  containing the whitespace.  Strictly speaking, that is trailing
  whitespace nonetheless, but displaying it specially in that case looks
  ugly while you are typing in new text.  In this special case, the
  location of point is enough to show you that the spaces are present.

Because of this, when you move the cursor, the display engine cannot
assume that the display remains unchanged, because it needs to see if
the cursor happens to be after a stretch of trailing whitespace, in
which case, that whole stretch of whitespace needs to be redrawn as
well.  For the same reason, other optimizations, like those which
reuse portions of the previously displayed window, are abandoned.

I've looked at the optimizations we disable in this case, and I cannot
see anything wrong in those decisions, given the way this feature
works.

We could try adding an optional feature which doesn't turn off the
special display of trailing whitespace when the cursor is at the end
of a line that ends in whitespace, that might allow us to re-enable
these optimizations.  Would users like that?

Other than that, I don't see how this could be helped, except by some
thorough redesign of how this feature works.  I don't immediately see
how to do that, but maybe someone else does, and is motivated to work
on this.

> Also this creates minor glitches in displaying text on buffer
> (sudden disappearance and appearence of some text) when CPU is already
> enough busy.

If your CPU is very busy, then adding a few percents to it might
indeed produce such jerky redisplay, I think.





      reply	other threads:[~2016-04-21 14:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21  6:03 bug#23327: 25.0.92; show-trailing-whitespace uses too much cpu Mohammed Sadik
2016-04-21 14:16 ` 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=837ffr6o9j.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=23327@debbugs.gnu.org \
    --cc=sadiq@sadiqpk.org \
    /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.