all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: 'Ihor Radchenko' <yantar92@gmail.com>
Cc: 35453@debbugs.gnu.org
Subject: bug#35453: 26.1; Poor performance of vertical-motion in large org buffer
Date: Sun, 28 Apr 2019 18:20:09 +0300	[thread overview]
Message-ID: <83zhoatavq.fsf@gnu.org> (raw)
In-Reply-To: <87pnpaob79.fsf@yantar92-laptop.i-did-not-set--mail-host-address--so-tickle-me> (message from 'Ihor Radchenko' on Thu, 25 Apr 2019 14:23:06 +0800)

> From: 'Ihor Radchenko' <yantar92@gmail.com>
> Date: Thu, 25 Apr 2019 14:23:06 +0800
> 
> C-n and C-p are extremely slow (>10 sec to move one visual line) when
> moving around a large org buffer in overview state, especially right
> after opening the file.
> The issue seems to be with low-level vertical-motion command - M-:
> (vertical-motion 1) also takes >10sec on some lines.
> 
> Steps to reproduce (emacs -Q):
> 1. Open the attached org file
> 2. C-n, C-n, C-n, C-n
> 3. Observe emacs hanging for >10sec. 

I'm not sure I understand: is your problem with vertical-motion, or in
general with moving by lines in that file's buffer?

If the problem is the latter, then my advice to Org users is to use
"C-c C-n/C-p" and "C-c C-f/C-b", not the normal cursor motion
commands, because Org makes the latter very slow when a large portion
of a large buffer is hidden.  I will now try to explain why.

This buffer's size is around 1MB and 42K lines, and the part between
the 3rd and the 4th heading holds its lion's share: almost 40K lines
of text.  When C-n calls vertical-motion, the latter needs to find the
buffer position displayed directly below the place where you typed
C-n.  Since much of the text between these places, vertical-motion
needs to skip the invisible text as quickly as possible, because from
the user's POV that text "doesn't exist": it isn't on the screen.
However, Org makes this skipping exceedingly hard, because (1) it uses
overlays (as opposed to text properties) to hide text, and (2) it puts
an awful lot of overlays on the hidden text: there are 18400 overlays
in this file's buffer, 17500 of them between the 3rd and the 4th
heading.  Because of this, vertical-motion must examine each and every
overlay as it moves through the text, because each overlay can
potentially change the 'invisible' property of text, or it might have
a display string that needs to be displayed.  So instead of skipping
all that hidden text in one go, vertical-motion loops over those 17.5K
overlays examining the properties of each one of them.  And that takes
time.

Profiling shows that 80%(!) of the CPU time is spent in the function
overlays_at which looks for overlays at a given buffer position, and
10% more in marker_position (because overlay endpoints are markers).
So 90% of the time you wait for the cursor to move is spent processing
overlays.

Compare this with Outline mode, which places a single overlay on the
entire hidden text between headings.  If you visit the same file in
Outline mode, C-n will be much, much faster.

So with the current implementation of Org and overlays, Org users are
well advised not to make such large bodies in their Org files, and if
they do, definitely not to use C-n and C-p for vertical motion.

Of course, if someone comes up with ideas how to speed up
vertical-motion without changing what Org does with overlays and/or
how overlays are implemented, such ideas will be most welcome.





  reply	other threads:[~2019-04-28 15:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25  6:23 bug#35453: 26.1; Poor performance of vertical-motion in large org buffer 'Ihor Radchenko'
2019-04-28 15:20 ` Eli Zaretskii [this message]
2019-05-05  1:05   ` Ihor Radchenko
2019-05-05  1:05   ` Ihor Radchenko
2019-05-05 15:58     ` Eli Zaretskii
2019-05-05 15:58     ` Eli Zaretskii
2019-05-18 10:36       ` Ihor Radchenko
2022-10-29  9:02         ` Ihor Radchenko
2022-10-29 10:42           ` Eli Zaretskii
2022-10-29 13:31             ` Stefan Kangas
2019-05-18 10:36       ` Ihor Radchenko

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=83zhoatavq.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=35453@debbugs.gnu.org \
    --cc=yantar92@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.