all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-devel@gnu.org,  Eli Zaretskii <eliz@gnu.org>,
	eller.helmut@gmail.com,
	 Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: MPS: dangling markers
Date: Fri, 28 Jun 2024 06:07:28 +0200	[thread overview]
Message-ID: <m27ce9soan.fsf@pro2.fritz.box> (raw)
In-Reply-To: <87v81u85hv.fsf@localhost> (Ihor Radchenko's message of "Thu, 27 Jun 2024 21:01:32 +0000")

Ihor Radchenko <yantar92@posteo.net> writes:

> Related: bug#71644, bug#63040
>
> When running the scratch/igc branch, I noticed a severe slowdown (10x or
> more) of redisplay on my large Org buffers.
>
> - The redisplay manifests itself as I build agenda multiple times
>   (agenda creates many new markers).
>
> - perf points to (1) itree lookup; (2) bytepos<->charpos, which implies
>   that things may be related to the number of allocated markers and
>   overlays.
>
> - I observe things slowing down as the number of "PVEC_MARKER" in the
>   output of `igc-info' grows.
>
> - Forcing (igc--collect) returns speed to normal

Ok, interesting.

> I believe that my observation reveals one important point that may need
> to be considered when using MPS:
>
> We may need to more careful about cases in Emacs C code that traverse
> object lists that may contain unreferenced objects.  Because MPS does
> not perform GC as regularly as the traditional mark-and-sweep, some
> unreferenced objects may remain live and present in internal data
> structures for a long time.

Maybe it's helpful when I describe what I do for the buffer markers, as
opposed to what is done currently.

In master, buffer_text::markers is a singly-linked list of Lisp_Markers,
using Lisp_Marker::next. In the sweep phase of GC, in sweeo_buffers, we
iterate over all buffers and remove markers from the list that were not
marked during the mark phase of GC. The list itself is left alone in the
mark phase, so that references from these lists don't keep markers
alive. The buffer markers thus acts as a weak list. Since
garbage_collect is called often enough, markers are swiftly remnoved
from the marker lists.

What I've done in igc so far: buffer_text::markers is a Lisp vector and
Lisp_Marker::next is gone. Elements of the vector are either nil or a
marker. The vector is weak, entries for markers that are not referenced
from somewhere else are set to nil eventually. Adding and removing
markers is done naively in O(N) where N is the size of the vector. The
vectors are resized if needed by doubling their size. They are never
shrunk. Iteration goes over the whole vector, ignoring nil entries.

Possibly, there is some potential for improvement :-).

What we can't do is hope to make this weakness more "eager" so to say.
Entries in weak vectors are reset to nil, but when MPS thinks it's a
good time doing that. (It's BTW the wrong mental model to think of MPS
doing GC at a specific time. It's more like doing GC work all the time,
concurrently.) But it's true that MPS doesn't "eagerly" reset entries in
these vectors. And there's no way, to my knowledge, to force it to do
that other than to trigger a full GC.

Ideas welcome, or better yet implemenations :-). I'm currently not
working on this.

> AFAIK, at least overlays, buffers, and markers are used in C code within
> object lists/trees are often traversed in full. If objects in these
> lists are not regularly garbage-collected, we may end up in situation
> when dead objects significantly impact performance. I believe that what
> I observe locally is exactly the described scenario.

Probably.



      parent reply	other threads:[~2024-06-28  4:07 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27 21:01 MPS: dangling markers Ihor Radchenko
2024-06-27 21:24 ` Stefan Monnier
2024-06-28  4:14   ` Gerd Möllmann
2024-06-28 16:37     ` Ihor Radchenko
2024-06-28 16:47       ` Gerd Möllmann
2024-06-28 16:52         ` Ihor Radchenko
2024-06-28 16:56           ` Gerd Möllmann
2024-06-28 17:18             ` Ihor Radchenko
2024-06-28 17:44               ` Gerd Möllmann
2024-06-29  3:57               ` Gerd Möllmann
2024-06-29 14:34                 ` Ihor Radchenko
2024-06-29 14:56                   ` Gerd Möllmann
2024-06-29 16:29                     ` Eli Zaretskii
2024-06-29 17:09                       ` Gerd Möllmann
2024-06-29 17:17                         ` Gerd Möllmann
2024-06-29 17:23                           ` Eli Zaretskii
2024-06-29 18:02                             ` Gerd Möllmann
2024-06-29 18:11                               ` Eli Zaretskii
2024-06-29 18:19                                 ` Gerd Möllmann
2024-06-29 19:51                                 ` Ihor Radchenko
2024-06-29 21:50                                   ` Gerd Möllmann
2024-06-29 22:33                                     ` Pip Cet
2024-06-30  4:41                                       ` Gerd Möllmann
2024-06-30  6:56                                         ` Gerd Möllmann
2024-06-30  9:51                                         ` Pip Cet
2024-06-30 11:02                                           ` Gerd Möllmann
2024-06-30 12:54                                             ` Pip Cet
2024-06-30 13:15                                               ` Gerd Möllmann
2024-06-30 19:02                                                 ` Pip Cet
2024-06-30 19:22                                                   ` Gerd Möllmann
2024-06-30 20:15                                                     ` Pip Cet
2024-07-01  4:22                                                       ` Gerd Möllmann
2024-07-01 17:14                                                         ` Pip Cet
2024-07-01 18:20                                                           ` Gerd Möllmann
2024-07-01 18:50                                                           ` Eli Zaretskii
2024-07-01 19:04                                                             ` Pip Cet
2024-07-01 19:07                                                               ` Eli Zaretskii
2024-07-01 19:43                                                             ` Gerd Möllmann
2024-07-01 18:56                                                           ` Eli Zaretskii
2024-07-01 21:08                                                             ` Pip Cet
2024-07-02 11:25                                                               ` Eli Zaretskii
2024-07-03 18:46                                                                 ` Pip Cet
2024-07-03 19:20                                                                   ` Eli Zaretskii
2024-06-29 22:59                                     ` Stefan Monnier
2024-06-30  5:02                                       ` Gerd Möllmann
2024-06-30  5:29                                         ` Eli Zaretskii
2024-06-30 15:04                                         ` Stefan Monnier
2024-06-30  5:11                                       ` Eli Zaretskii
2024-06-30  4:57                                     ` Eli Zaretskii
2024-06-30  5:36                                       ` Gerd Möllmann
2024-06-30 12:25                                         ` Ihor Radchenko
2024-06-29 17:19                         ` Ihor Radchenko
2024-06-29 18:05                           ` Gerd Möllmann
2024-06-29 18:10                             ` Eli Zaretskii
2024-06-29 18:17                               ` Gerd Möllmann
2024-06-29 18:28                                 ` Ihor Radchenko
2024-06-29 17:20                         ` Eli Zaretskii
2024-06-29 18:04                           ` Gerd Möllmann
2024-06-29 17:16                     ` Stefan Monnier
2024-06-29 18:12                       ` Gerd Möllmann
2024-06-29 18:30                         ` Stefan Monnier
2024-06-29 18:52                           ` Gerd Möllmann
2024-06-29 21:20                             ` Gerd Möllmann
2024-06-29 21:38                               ` Gerd Möllmann
2024-06-30  7:11                                 ` Gerd Möllmann
2024-06-30  7:27                                   ` Gerd Möllmann
2024-06-30  7:45                                     ` Ihor Radchenko
2024-06-30 10:44                                       ` Gerd Möllmann
2024-06-30 11:23                                       ` Ihor Radchenko
2024-06-30 11:25                                         ` Gerd Möllmann
2024-06-30 11:31                                           ` Ihor Radchenko
2024-06-30 12:13                                             ` Gerd Möllmann
2024-06-30 12:18                                               ` Ihor Radchenko
2024-06-30 12:17                                     ` Ihor Radchenko
2024-06-30 12:28                                       ` Gerd Möllmann
2024-06-30 12:38                                         ` Ihor Radchenko
2024-06-30 12:48                                           ` Gerd Möllmann
2024-06-30 15:21                                             ` Ihor Radchenko
2024-06-30 15:32                                               ` Gerd Möllmann
2024-06-30 12:49                                           ` Eli Zaretskii
2024-06-29 15:17   ` Ihor Radchenko
2024-06-28  4:07 ` Gerd Möllmann [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=m27ce9soan.fsf@pro2.fritz.box \
    --to=gerd.moellmann@gmail.com \
    --cc=eliz@gnu.org \
    --cc=eller.helmut@gmail.com \
    --cc=emacs-devel@gnu.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.