unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Andrew Cohen <acohen@ust.hk>
To: 64391@debbugs.gnu.org
Cc: Gregory Heytings <gregory@heytings.org>
Subject: bug#64391: 30.0.50; buffer narrowing slowdown regression in emacs 29
Date: Sat, 01 Jul 2023 08:15:25 +0800	[thread overview]
Message-ID: <877crkcwrm.fsf@ust.hk> (raw)

[-- Attachment #1: Type: text/plain, Size: 2151 bytes --]


I have noticed a huge slowdown in parsing email headers in gnus. After
some debugging with help from Mattias Engdegård, the problem has been
traced to the narrowing code introduced in

commit ba9315b1641b483f2bf843c38dcdba0cd1643a55 (HEAD)
Merge: aef803d6c3d a3b654e069e
Author: Gregory Heytings <gregory@heytings.org>
Date:   Thu Nov 24 14:21:30 2022 +0100

    Merge master into feature/improved-locked-narrowing.

Gnus populates a buffer with headers from a set of email messages and
then parses them by: narrowing the buffer to the headers for an
individual message; parsing the headers; widening; and then repeating
for the next message.  As part of the parsing the headers are "unfolded"
so that each header doesn't include line breaks. I noticed that for a
long list of messages (10,000) this takes between one and two orders of
magnitude more time in Emacs 30 than in Emacs 28. Unfolding all the
headers in the full buffer before the parsing process removes most of
the slowdown. The slowdown seems to grow quadratically with the size of
the buffer.

The problem seems fairly general and Mattias has produced a simple test
case to demonstrate the issue (code at the end of this message):

1. Create a buffer with 100,000 lines each containing two characters  "ab".
2. Loop through the buffer narrowing to each line, and immediately widening
    back to the full buffer (so no change is made to the buffer
    contents).
3.  Loop through the buffer removing the first character of each line.

This takes a very long time compared with reversing the order of 2. and 3.

Emacs 28.2
Modify after narrowing:  0.173 s elapsed, 0 GCs, 0.000 s GC, 0.173 s non-GC
Modify before narrowing: 0.160 s elapsed, 0 GCs, 0.000 s GC, 0.160 s non-GC

Emacs 29.0.92
Modify after narrowing:  4.454 s elapsed, 9 GCs, 0.115 s GC, 4.339 s non-GC
Modify before narrowing: 0.291 s elapsed, 9 GCs, 0.114 s GC, 0.177 s non-GC

The problem may be the creation of markers in the narrowing process that
slows down further mutation. (Also note that the new code has introduced
some significant GC that was previously absent).


[-- Attachment #2: Demonstrate narrowing slowdown --]
[-- Type: application/emacs-lisp, Size: 1595 bytes --]

[-- Attachment #3: Type: text/plain, Size: 20 bytes --]




-- 
Andrew Cohen

             reply	other threads:[~2023-07-01  0:15 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-01  0:15 Andrew Cohen [this message]
2023-07-01  2:45 ` bug#64391: bug 64391 wrong git info Andrew Cohen
2023-07-01  4:59 ` bug#64391: more info Andrew Cohen
2023-07-01 11:37   ` bug#64391: buffer narrowing slowdown regression in emacs 29 Mattias Engdegård
2023-07-01 12:08     ` Eli Zaretskii
2023-07-01 12:52       ` Mattias Engdegård
2023-07-02  7:35         ` Gregory Heytings
2023-07-05 11:57           ` Eli Zaretskii
2023-07-06 14:41             ` Gregory Heytings
2023-07-06 17:33               ` Gregory Heytings
2023-07-06 18:22                 ` Eli Zaretskii
2023-07-06 18:45                   ` Gregory Heytings
2023-07-07  9:30                     ` Mattias Engdegård
2023-07-07 10:00                       ` Gregory Heytings
2023-07-07 10:23                         ` Eli Zaretskii
2023-07-07 10:31                           ` Gregory Heytings
2023-07-07 12:41                             ` Eli Zaretskii
2023-07-07 12:46                               ` Gregory Heytings
2023-07-07 11:33                         ` Mattias Engdegård
2023-07-07 12:42                           ` Gregory Heytings
2023-07-07 15:49                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-08 20:58                               ` Gregory Heytings
2023-07-08 21:42                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-08 22:21                                   ` Gregory Heytings
2023-07-08 23:22                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09 16:03                                       ` Gregory Heytings
2023-07-09 18:57                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09  6:03                                     ` Eli Zaretskii
2023-07-09  8:35                                       ` Gregory Heytings
2023-07-09  8:52                                         ` Eli Zaretskii
2023-07-09 16:04                                           ` Gregory Heytings
2023-07-09 16:39                                             ` Eli Zaretskii
2023-07-09 18:03                                               ` Gregory Heytings
2023-07-09 18:52                                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09 19:19                                                   ` Gregory Heytings
2023-07-09 19:42                                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09 19:44                                                       ` Gregory Heytings
2023-07-09 19:03                                                 ` Eli Zaretskii
2023-07-09 19:06                                                   ` Eli Zaretskii
2023-07-09 19:29                                                     ` Gregory Heytings
2023-07-07 10:27                       ` Eli Zaretskii
2023-07-07 11:27                         ` Mattias Engdegård
2023-07-07 12:50                           ` Eli Zaretskii
2023-07-07 16:49                             ` Mattias Engdegård
2023-07-07 18:22                               ` Eli Zaretskii
2023-07-08  8:01                 ` Eli Zaretskii
2023-07-08 19:41                   ` Gregory Heytings
2023-07-02  9:37         ` Mattias Engdegård
2023-07-01  7:07 ` bug#64391: 30.0.50; " Eli Zaretskii
2023-07-01  7:31   ` Andrew Cohen
2023-07-01  8:09     ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=877crkcwrm.fsf@ust.hk \
    --to=acohen@ust.hk \
    --cc=64391@debbugs.gnu.org \
    --cc=gregory@heytings.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).