all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alex Gramiak <agrambot@gmail.com>
To: Keith David Bershatsky <esq@lawlist.com>
Cc: eliz@gnu.org, dancol@dancol.org, emacs-devel@gnu.org
Subject: Re: NS port: How to debug excessive garbage collection?
Date: Sun, 14 Apr 2019 17:31:16 -0600	[thread overview]
Message-ID: <87pnpotb97.fsf@gmail.com> (raw)
In-Reply-To: <m2o958xtd7.wl%esq@lawlist.com> (Keith David Bershatsky's message of "Sun, 14 Apr 2019 12:46:28 -0700")

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

Keith David Bershatsky <esq@lawlist.com> writes:

> The attched patch (debug_mwe_001.diff) is a minimal working example that demonstrates the issue on all three platforms (X11, W32, NS) using the GUI version of Emacs built from the master branch as of 04/08/2019 (a038df77de7b1aa2d73a6478493b8838b59e4982).
>
> The snippet that I am pasting and evaluating in the minibuffer is as follows:
>
> (progn
>   (find-library "simple")
>   (fundamental-mode)
>   (blink-cursor-mode -1)
>   (global-eldoc-mode -1)
>   (setq timer-list nil
>         timer-idle-list nil
>         crosshairs t))
>
> Here are Youtube links to screen recordings of the minimal working example on all three platforms:
>
> NS (screen recording):  https://youtu.be/4IzXfP2j2GY
>
> X11 (screen recording):  https://youtu.be/zrRH72qdmx0
>
> W32 (screen recording):  https://youtu.be/cfIG4fbkesY
>
> MINIMAL WORKING EXAMPLE:
>
> 1.  Imaginary / Pretend:  We imagine that all fake cursors are erased at the outset of update_window while w->current_matrix is still valid; i.e., before scrolling_window does its thing.
>
> 2.  The master cache of fake cursors (w->ch_cache) is set to Qnil.
>
> 3.  Imaginary / Pretend:  We imagine .... As to the rows in the w->desired_matrix that must be updated with update_text_area, we draw fake cursors immediately after draw_glyphs finishes updating the row.  As we are laying fake cursors, we use a temporary cache (w->mc_temp_cache) to store the relevant data so that we can redraw any fake cursors that get erased because they are left/right_overwritten as determined by draw_glyphs.  Once the row has been updated with fake cursors, we set the termporary cache (w->mc_temp_cache) to Qnil and we set the master cache with the new data -- appending new data if the cache is non-nil.
>
> 4.  As to all remaining rows that are not updated with update_text_area (which uses w->desired_matrix), we use the w->current_matrix and draw/cache the fake cursors using the same approach as mentioned in the preceding step; i.e., a temporary cache (w->mc_temp_cache) so that we can fix any fake cursors that got left/right_overwritten and then that cache is set to Qnil and the master cache (w->mc_cache) is updated.
>
> In the above minimal working example, the window Lisp_Object caches are rather simple:
>
> '((make_fixnum (1))
>   (make_fixnum (2))
>   (make_fixnum (3))
>   ...
>   (make_fixnum (99)))

If I'm looking at this right, the float issue is now resolved, but
there's still a cons cell issue. A way to fix this in the MWE is to
reuse the cons cells rather than making new cells each time. I've
included a diff below (that just includes the parts I touched on your
diff) that should solve, or at least mitigate, your problem. Hopefully
it's useful.

Looking at your actual implementation though, I don't see a reason for
your cache to be a Lisp_Object at all; am I missing something? It seems
that you could just use a C array of length 14. Not making any cons
cells at all is the best approach if you can do so.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mc --]
[-- Type: text/x-patch, Size: 2141 bytes --]

diff --git a/src/dispnew.c b/src/dispnew.c
index ccb08ec1b9..068296212f 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3497,6 +3497,40 @@ update_window (struct window *w, bool force_p)
 
     set_cursor:
 
+
+/* *************************************************************************** */
+/* MULTIPLE-CURSORS */
+
+   for (struct glyph_row *desired_row = MATRIX_ROW (desired_matrix, 0);
+        desired_row < end
+        && (force_p || !input_pending)
+        && BUFFERP (w->contents)
+        && (!NILP (BVAR (XBUFFER (w->contents), crosshairs)));
+        ++desired_row)
+    {
+      if (desired_row->enabled_p)
+        continue;
+      wset_mc_temp_cache (w, Qnil);
+      int vpos = MATRIX_ROW_VPOS (desired_row, desired_matrix);
+      struct glyph_matrix *current_matrix = w->current_matrix;
+      struct glyph_row *current_row = MATRIX_ROW (current_matrix, vpos);
+      if (current_row->enabled_p)
+        {
+          Lisp_Object head = w->mc_temp_cache;
+          // Replace each element with the Lisp integer position
+          for (int i = 0; CONSP (head); ++i, head = XCDR (head))
+            XSETCAR (head, make_fixnum (i));
+        }
+    }
+
+   Lisp_Object head = w->ch_cache;
+   // Replace each element with the Lisp integer position
+   for (int i = 0; CONSP (head); ++i, head = XCDR (head))
+     XSETCAR (head, make_fixnum (i));
+
+/* *************************************************************************** */
+
+
       /* Update the header line after scrolling because a new header
 	 line would otherwise overwrite lines at the top of the window
 	 that can be scrolled.  */
diff --git a/src/window.c b/src/window.c
index ef2ed63850..6ee1f65d9f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4252,6 +4252,9 @@ make_window (void)
   w->scroll_bar_width = -1;
   w->scroll_bar_height = -1;
   w->column_number_displayed = -1;
+  /* Your MC caches -- note there's only 2 lists ever created for them */
+  w->ch_cache = Fmake_list (make_fixnum (100), Qnil);
+  w->mc_temp_cache = Fmake_list (make_fixnum (100), Qnil);
   /* Reset window_list.  */
   Vwindow_list = Qnil;
   /* Return window.  */

  reply	other threads:[~2019-04-14 23:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-14 19:46 NS port: How to debug excessive garbage collection? Keith David Bershatsky
2019-04-14 23:31 ` Alex Gramiak [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-04-16  5:51 Keith David Bershatsky
2019-04-16  2:57 Keith David Bershatsky
2019-04-16  5:26 ` Alex Gramiak
2019-04-15  5:19 Keith David Bershatsky
2019-04-15  2:55 Keith David Bershatsky
2019-04-15  3:44 ` Alex Gramiak
2019-04-14  7:41 Keith David Bershatsky
2019-04-13 18:07 Keith David Bershatsky
2019-04-13 21:41 ` Alex Gramiak
2019-04-14  3:47 ` Daniel Colascione
2019-04-13 16:31 Keith David Bershatsky
2019-04-13 17:02 ` Alex Gramiak
2019-04-13  5:55 Keith David Bershatsky
2019-04-13  6:48 ` Eli Zaretskii
2019-04-11 23:04 Keith David Bershatsky
2019-04-12  9:30 ` Eli Zaretskii
2019-04-11  3:27 Keith David Bershatsky
2019-04-11 14:14 ` 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

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

  git send-email \
    --in-reply-to=87pnpotb97.fsf@gmail.com \
    --to=agrambot@gmail.com \
    --cc=dancol@dancol.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=esq@lawlist.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.