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@posteo.net>
Cc: 58558@debbugs.gnu.org, larsi@gnus.org, monnier@iro.umontreal.ca
Subject: bug#58558: 29.0.50; re-search-forward is slow in some buffers
Date: Tue, 13 Dec 2022 15:11:17 +0200	[thread overview]
Message-ID: <83h6xzphxm.fsf@gnu.org> (raw)
In-Reply-To: <87tu1zd2c6.fsf@localhost> (message from Ihor Radchenko on Tue, 13 Dec 2022 10:28:57 +0000)

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: Eli Zaretskii <eliz@gnu.org>, monnier@iro.umontreal.ca,
>  58558@debbugs.gnu.org
> Date: Tue, 13 Dec 2022 10:28:57 +0000
> 
> Ok. I got around to try perf, and it turned out to be very easy to get
> started.
> 
> perf record -p <PID> + perf report already appear to give some clue:
> 
>     88.27%  emacs    emacs-30-vcs                      [.] buf_bytepos_to_charpos
>      3.75%  emacs    emacs-30-vcs                      [.] re_match_2_internal
>      1.35%  emacs    emacs-30-vcs                      [.] scan_sexps_forward
>      1.03%  emacs    emacs-30-vcs                      [.] re_search_2
>      0.65%  emacs    emacs-30-vcs                      [.] find_interval
>      0.56%  emacs    emacs-30-vcs                      [.] sub_char_table_ref
>      0.55%  emacs    emacs-30-vcs                      [.] lookup_char_property
> 
> The fraction of buf_bytepos_to_charpos increases over repeated benchmark
> runs.

So buf_bytepos_to_charpos is the main suspect now, I guess.  This
could happen because either (a) buf_bytepos_to_charpos is called more
times as session uptime progresses, or (b) because each call to
buf_bytepos_to_charpos becomes more and more expensive.  So I think
the first question is: how many times is buf_bytepos_to_charpos called
for each search, or, equivalently, is the CPU time per call used up by
buf_bytepos_to_charpos stays stable or goes up?  I think perf can
answer these questions if you ask nicely.

If the number of calls is the same, but each call becomes more and
more expensive, then the next step is to ask perf to produce a
detailed profile for each line of buf_bytepos_to_charpos, and see
which parts of it become more expensive.  I could think about a couple
of possible reasons for that, but I'd rather not speculate about
profiles, as that is known to produce wrong guesses.

Is the buffer in question being edited as time advances?  Or is buffer
text and everything else in the buffer left unchanged?

> In contrast, using find-file-literally produces
> 
>     34.44%  emacs    emacs-30-vcs                             [.] re_match_2_internal
>     25.55%  emacs    emacs-30-vcs                             [.] scan_sexps_forward
>     11.09%  emacs    emacs-30-vcs                             [.] re_search_2
>     ...
>     0.59%  emacs    emacs-30-vcs                             [.] buf_bytepos_to_charpos
> 
> with buf_bytepos_to_charpos taking diminishing cpu sample fraction.

That find-file-literally yields a buffer with a much faster
buf_bytepos_to_charpos is not surprising: when each character is a
single byte, the conversion is trivial, and buf_bytepos_to_charpos
returns immediately.  The puzzling part is not that
buf_bytepos_to_charpos is much more expensive in a buffer with
non-ASCII text, the puzzle is why it becomes more and more expensive
with time.

Thanks.





  reply	other threads:[~2022-12-13 13:11 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-16  1:26 bug#58558: 29.0.50; re-search-forward is slow in some buffers Ihor Radchenko
2022-10-16  9:19 ` Lars Ingebrigtsen
2022-10-16  9:34   ` Ihor Radchenko
2022-10-16  9:37     ` Lars Ingebrigtsen
2022-10-16 10:02       ` Ihor Radchenko
2022-10-16 10:04         ` Lars Ingebrigtsen
2022-10-16 10:53           ` Ihor Radchenko
2022-10-16 11:01             ` Lars Ingebrigtsen
2022-10-16 11:21               ` Eli Zaretskii
2022-10-16 14:23                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-17  0:56                   ` Ihor Radchenko
2022-10-18 11:50                     ` Lars Ingebrigtsen
2022-10-18 14:58                       ` Eli Zaretskii
2022-10-18 18:19                         ` Lars Ingebrigtsen
2022-10-18 18:38                           ` Eli Zaretskii
2022-12-13 10:28                           ` Ihor Radchenko
2022-12-13 13:11                             ` Eli Zaretskii [this message]
2022-12-13 13:32                               ` Ihor Radchenko
2022-12-13 14:28                                 ` Eli Zaretskii
2022-12-13 15:56                                   ` Ihor Radchenko
2022-12-13 16:08                                     ` Eli Zaretskii
2022-12-13 17:43                                       ` Ihor Radchenko
2022-12-13 17:52                                         ` Eli Zaretskii
2022-12-13 18:03                                           ` Ihor Radchenko
2022-12-13 20:02                                             ` Eli Zaretskii
2022-12-14 11:40                                               ` Ihor Radchenko
2022-12-14 13:06                                                 ` Eli Zaretskii
2022-12-14 13:23                                                   ` Ihor Radchenko
2022-12-14 13:32                                                     ` Eli Zaretskii
2022-12-14 13:39                                                       ` Ihor Radchenko
2022-12-14 14:12                                                         ` Eli Zaretskii
2022-12-13 18:15                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-13 18:40                                           ` Ihor Radchenko
2022-12-13 19:55                                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-13 20:21                                               ` Eli Zaretskii
2022-12-14 11:42                                                 ` Ihor Radchenko
2022-12-13 17:38                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-14 12:00                                       ` Ihor Radchenko
2022-12-14 12:23                                       ` Ihor Radchenko
2022-12-14 13:10                                         ` Eli Zaretskii
2022-12-14 13:26                                           ` Ihor Radchenko
2022-12-14 13:57                                             ` Eli Zaretskii
2022-12-14 14:01                                               ` Ihor Radchenko
2023-04-06 11:49                                                 ` Ihor Radchenko
2023-04-06 12:05                                                   ` Eli Zaretskii
2023-04-09 19:54                                                     ` Ihor Radchenko
2023-04-10  4:14                                                       ` Eli Zaretskii
2023-04-10 12:24                                                         ` Ihor Radchenko
2023-04-10 13:40                                                           ` Eli Zaretskii
2023-04-10 14:55                                                             ` Ihor Radchenko
2023-04-10 16:04                                                               ` Eli Zaretskii
2023-04-10 14:27                                                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-11 11:29                                                             ` Ihor Radchenko
2023-04-11 11:51                                                               ` Eli Zaretskii
2023-04-12 13:39                                                                 ` Ihor Radchenko
2023-04-12 14:06                                                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-12 14:30                                                                     ` Eli Zaretskii
2023-04-12 14:38                                                                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-12 15:22                                                                         ` Eli Zaretskii
2023-04-12 15:59                                                                           ` Alan Mackenzie
2023-04-12 14:38                                                                       ` Stephen Berman
2023-04-12 14:42                                                                       ` Ihor Radchenko
2023-04-12 14:39                                                                     ` Ihor Radchenko
2023-04-12 15:20                                                                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-12 23:23                                                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-13  4:33                                                                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-13 20:05                                                                             ` Ihor Radchenko
2023-04-13  4:52                                                                           ` Eli Zaretskii
2023-04-13  5:15                                                                             ` Eli Zaretskii
2023-04-12 18:31                                                                     ` Alan Mackenzie
2023-04-12 23:25                                                                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-13  4:43                                                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-13 12:09                                                                     ` Ihor Radchenko
2022-12-13 13:27                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-16 10:36         ` Eli Zaretskii
2023-02-19 12:17     ` Dmitry Gutov
2023-02-20 10:24       ` Ihor Radchenko
2023-02-20 14:54         ` Dmitry Gutov
2023-04-10  8:48 ` Mattias Engdegård
2023-04-10  9:57   ` Ihor Radchenko
2023-04-10 10:05     ` Mattias Engdegård

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=83h6xzphxm.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=58558@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=yantar92@posteo.net \
    /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.