unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 49127@debbugs.gnu.org, victor.nawothnig@icloud.com
Subject: bug#49127: Performance degradation in encode_coding_object
Date: Mon, 16 Aug 2021 20:06:32 +0200	[thread overview]
Message-ID: <4001E59F-63FF-4EF6-87B5-8A627871C4B8@acm.org> (raw)
In-Reply-To: <83sfz970av.fsf@gnu.org>

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

16 aug. 2021 kl. 19.43 skrev Eli Zaretskii <eliz@gnu.org>:

>> I don't know how this could ever work. We loop through the markers in the current buffer?
> 
> Yes.  Why do you think this loop is broken?

Because unless I misunderstood the code entirely, the current buffer has nothing to do with the operation at hand.

It's easy to reproduce the original problem: run Emacs in a terminal and make a buffer with many markers. See how the text displays slower with more markers. I've attached a short example; try (make-test-buffer 1000).

The attached patch fixes this problem.


[-- Attachment #2: lus.el --]
[-- Type: application/octet-stream, Size: 350 bytes --]

;;; -*- lexical-binding -*-

(defvar my-markers nil)

(defun make-test-buffer (n)
  (setq my-markers nil)
  (with-current-buffer (get-buffer-create "test-buffer")
    (erase-buffer)
    (dotimes (i 1000)
      (insert (format "%8d " i))
      (dotimes (_ n)
        (push (point-marker) my-markers))
      (insert "abcdefghijklmnopqrstuvwxyz\n"))))


[-- Attachment #3: 0001-Fix-marker-traversion-in-encode_coding_object.patch --]
[-- Type: application/octet-stream, Size: 1289 bytes --]

From d38eace17a24ed2d15a3bf069e1aaf05a495e077 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Mon, 16 Aug 2021 19:57:34 +0200
Subject: [PATCH] Fix marker traversion in encode_coding_object

* src/coding.c (encode_coding_object): Only traverse markers if we are
encoding to and from buffers, and use the right buffer when doing so.

This also fixes a performance problem when running in a terminal and
the displayed buffer has many markers (bug#49127).
Reported by Victor Nawothnig.
---
 src/coding.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/coding.c b/src/coding.c
index 87b55aecc0..599ed48b2e 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -8275,11 +8275,11 @@ encode_coding_object (struct coding_system *coding,
 
   attrs = CODING_ID_ATTRS (coding->id);
 
-  if (EQ (src_object, dst_object))
+  if (EQ (src_object, dst_object) && BUFFERP (dst_object))
     {
       struct Lisp_Marker *tail;
 
-      for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
+      for (tail = BUF_MARKERS (XBUFFER (dst_object)); tail; tail = tail->next)
 	{
 	  tail->need_adjustment
 	    = tail->charpos == (tail->insertion_type ? from : to);
-- 
2.21.1 (Apple Git-122.3)


  reply	other threads:[~2021-08-16 18:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <EC5DED64-8465-45A3-B20C-8D21F70E0A34@acm.org>
2021-08-16 17:43 ` bug#49127: Performance degradation in encode_coding_object Eli Zaretskii
2021-08-16 18:06   ` Mattias Engdegård [this message]
2021-08-16 18:50     ` Eli Zaretskii
2021-08-16 20:04       ` Mattias Engdegård
2021-08-17 12:34         ` Eli Zaretskii
2021-08-17 13:06           ` Mattias Engdegård
2021-08-17 14:05             ` Eli Zaretskii
2021-08-17 16:07               ` Mattias Engdegård
2021-08-17 17:16                 ` Eli Zaretskii
2021-08-18 11:04                   ` Mattias Engdegård
2021-08-18 11:43                     ` Eli Zaretskii
2021-08-18 12:21                       ` Mattias Engdegård
2021-08-18 13:23                         ` Eli Zaretskii
2021-08-18 13:32                           ` Mattias Engdegård
2021-08-18 13:39                             ` Eli Zaretskii
2021-08-18 13:54                               ` Mattias Engdegård
2021-08-18 13:59                                 ` Eli Zaretskii
2021-08-18 15:24                                   ` Mattias Engdegård
2021-08-18 14:34                             ` Lars Ingebrigtsen
2021-08-20 23:24                               ` Michael Welsh Duggan
2021-08-21  6:34                                 ` Eli Zaretskii
2021-06-20  6:30 Victor Nawothnig via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-20  9:04 ` Eli Zaretskii
2021-06-24 16:49   ` Eli Zaretskii
2021-07-25  7:10     ` Eli Zaretskii
2021-08-15 15:07       ` Eli Zaretskii
2021-08-17 12:35         ` 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=4001E59F-63FF-4EF6-87B5-8A627871C4B8@acm.org \
    --to=mattiase@acm.org \
    --cc=49127@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=victor.nawothnig@icloud.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 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).