unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@permabit.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 11822@debbugs.gnu.org
Subject: bug#11822: 24.1; emacsclient terminal mode captures escape characters as text
Date: Thu, 10 Sep 2015 02:59:06 -0400	[thread overview]
Message-ID: <6e613irc91.fsf@just-testing.permabit.com> (raw)
In-Reply-To: <83si6n65ld.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 09 Sep 2015 17:16:14 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Ken Raeburn <raeburn@permabit.com>
>> Cc: 11822@debbugs.gnu.org
>> Date: Tue, 08 Sep 2015 15:54:49 -0400
>> 
>> > I'm still not following you: what do input events have to do with the
>> > need to redisplay or not redisplay some frame(s)?
>> 
>> If we don't need to update a frame, that's great. But I'm also thinking
>> about cases where a frame does need updating but isn't on the
>> currently-used display. Though for it to be important in this context,
>> updating text probably don't matter much(?), just cases where we
>> actually need to stop and wait for a reply, which probably means changes
>> to face definitions like updating the foreground color.
>
> I don't follow: what replies did you have in mind?  Replies from whom
> or what?

Replies from the X server to LookupColor or AllocColor requests.

That's when the round-trip time and the number of round trips become
important. If we're just sending text-drawing requests, and if there's
enough bandwidth or socket buffer space (neither of which is actually
guaranteed), we shouldn't need to wait, and it shouldn't cause any
significant delay for updates to other frames. So once the
global-variable aspects are addressed, the sort of delay I'm dealing
with should only come up for things like changes to colors in faces that
are used on multiple displays.

> Emacs redraws windows on frames that require redrawing because
> something happened that affects how the visible portion of the windows
> look on the glass.  Emacs doesn't consider some changes more important
> than others, nor waits for any replies, when it decides that changes
> to buffers or strings require redisplay of some window.
>
> I don't think the idea of holding off some display updates for
> whatever reasons will fly, because users rightfully expect the display
> to be up to date, unless Emacs is busy computing something.

I didn't mean having them seconds or minutes out of date. What I'm
thinking of -- assuming for the sake of argument that we're still
concerned about types of changes that'll still require changes on
multiple frames even after the global-variable issues are addressed,
like changing the default face's foreground color -- would be something
like updating faces and then content on one frame, then going on to the
next and updating faces and then content, but preempting the rest ASAP
if user input is received. If recompute_basic_faces is called, since it
triggers a lot of round trips, at least one or two possible preemption
points in the middle of that sequence.

Plus more intelligent ordering of frames for updating (see below). And
image handling probably fits in there too somewhere.

If there's no input received during the process, or after the input is
dealt with, all the face computations and display updates should proceed
normally and all frames should become up-to-date.

I was thinking in terms of delays or idle timers (e.g., wait for "idle"
time of 0.0001s then do this next update increment) as a possible simple
and stupid way to implement that, driven by the input-handling part of
the program, but reviewing what I'm learning about Emacs redisplay, it
doesn't really make sense.

>> Would changing sizes for a face cause the face to be recomputed from
>> scratch?
>
> It doesn't in my testing (I tried "C-x C-+").  You can easily try that
> yourself: put a breakpoint on recompute_basic_faces, and see if it
> breaks when you change the face size.

I tried it in the scratch buffer in a new Emacs process. It doesn't call
recompute_basic_faces, but it did call realize_face twice, and
XParseColor and x_alloc_nearest_color_1 each four times. So that's eight
round trips that seem unnecessary as we should already have the color
definitions and allocated color cells.

>> Giving updates to a remote display that's not the currently-active one
>> lower priority than dealing with input on the active display could let
>> us be more responsive on the active display, but at the risk of leaving
>> the other display slightly out of date in occasional cases where it
>> might matter (a second person working at the second display at the same
>> time, both displays mapping to the same physical display via multiple
>> ssh connections, etc).
>
> I'm not sure I understand the practical meaning of "lower priority".
> When the display engine decides that more than one window needs to be
> redisplayed, it iterates through all the frames, one by one, and on
> each frame iterates through all of its windows.  The order of the
> frame traversal is independent of their displays, and it is
> sequential.
>
> Given this general description, what would "lower priority" mean in
> practice?

Reorder the frame traversal. If in some circumstances a full redisplay
process updating multiple frames can be slow (fewer such circumstances
after the work Stefan outlined and has started gets done, but I expect
some cases will remain), and if user input can preempt completion of
redisplay (I see comments indicating it can but don't know precisely how
or how well it works with X), which frames do we want updated first or
more often? Near as I can tell, it's done by the age of the frame, from
newest to oldest, because newer ones are added to Vframe_list at the
front. My comments about the current display vs other displays vs tty
frames are just ideas of what a better heuristic might look like.

If we effectively do face recomputation across all frames needing it as
a separate pass before doing screen updates, though, it might not help.
(For face updates, at least... I haven't traced through the image
handling.)

> And anyway, I don't think we should do anything that could produce
> frames that are not up to date, because we will be crucified by users.
> I can easily envision a use case where frames on the
> currently-inactive display are actively watched by a user, perhaps
> even the same user who types at the currently-active display.

Yep, that's why they should all get updated ASAP if some input doesn't
preempt redisplay. It doesn't argue for order-of-creation processing
though.

> We can justify partially outdated display when Emacs has something to
> do, but we cannot justify that when Emacs is idle.
>
> However, Emacs should refrain from redrawing iconified frames, so one
> possible method of saving some time should be to leave frames on the
> inactive display iconified.  Did you try that, and if so, did that
> help?

I haven't. I tried remotely iconifying it via Lisp code, but Emacs still
thought it was visible. Now that I'm at home, I'll try to leave it
iconified before heading back to work.

>> > Anyway, I think preventing frames from being unnecessarily redisplayed
>> > will bring larger benefits than just avoiding realization of some
>> > faces.
>> 
>> Perhaps so. I think we've got inefficiencies at multiple levels:
>> updating frames that don't need it; updating faces that don't need it
>> (on frames where something does or may need updating); redundant color
>> queries to a display; probably some issues around image handling. Fixing
>> any of them would be an improvement, but addressing more than one is
>> probably better still.
>
> My reading of the discussion and your backtraces indicate that all of
> that stems from a single problem: when we create or update faces, we
> set a global flag that causes faces to be recomputed on all frames.
> This then snowballs into the need to reload colors and redraw all
> frames.

I think that's the worst part for my new-frame-with-multiple-displays
case, but I don't think it's the only area of the code that could be
improved.

I took a look at the calls to x_alloc_nearest_color_1. In creating an
initial frame with "emacs -Q", I get over two hundred calls, and every
one requires a round-trip to the server. But there were only 13 distinct
RGB color values passed. The most popular values passed were these:

     88 x_alloc_nearest_color_1(0000/0000/0000) (white)
     71 x_alloc_nearest_color_1(ffff/ffff/ffff) (black)
     15 x_alloc_nearest_color_1(bfbf/bfbf/bfbf) (grey75)

Then there's XParseColor; over 2300 calls, but only about 9% require
round-trips to the server, the rest using the "#RRGGBB" syntax that gets
parsed locally. I haven't traced which part of the program accounts for
what fraction of the calls.

Eliminating unnecessary cache clearing might reduce these, maybe by a
factor of two or more, but that's still excessive; and 100 round trips
with a 30ms RTT would still contribute 3 seconds to the time needed to
finish setting up the initial frame. Now, if instead we had just *one*
call to XAllocNamedColor for "white", and one for "black", etc....

Ken





  reply	other threads:[~2015-09-10  6:59 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-30  0:08 bug#11822: 24.1; emacsclient terminal mode captures escape characters as text Ken Raeburn
2012-06-30  5:55 ` Eli Zaretskii
2012-07-31 21:06   ` Ken Raeburn
2012-08-08  3:13     ` Ken Raeburn
2012-08-08  4:52       ` Dan Nicolaescu
2012-08-08  9:26         ` Ken Raeburn
2012-08-09 21:12           ` Ken Raeburn
2012-08-10  6:16             ` Eli Zaretskii
2012-08-10  7:27               ` Ken Raeburn
2012-08-10  7:46                 ` Eli Zaretskii
2012-08-10  8:08                   ` Eli Zaretskii
2015-09-07 21:09                     ` Ken Raeburn
2015-09-08  1:29                       ` Stefan Monnier
2015-09-08  4:29                         ` Eli Zaretskii
2015-09-08  6:53                         ` Ken Raeburn
2015-09-08 13:03                           ` Stefan Monnier
2015-09-08 13:11                           ` Stefan Monnier
2015-09-08 17:21                             ` Eli Zaretskii
2015-09-08  4:48                       ` Eli Zaretskii
2015-09-08 10:15                         ` Ken Raeburn
2015-09-08 13:35                           ` Stefan Monnier
2015-09-08 17:33                           ` Eli Zaretskii
2015-09-08 19:54                             ` Ken Raeburn
2015-09-09 14:16                               ` Eli Zaretskii
2015-09-10  6:59                                 ` Ken Raeburn [this message]
2015-09-10 15:36                                   ` Eli Zaretskii
2015-09-10 17:56                                     ` Stefan Monnier
2015-09-10 18:06                                       ` Eli Zaretskii
2015-09-11 12:56                                         ` Stefan Monnier
2015-09-11 13:53                                           ` Eli Zaretskii
2015-09-11 16:53                                             ` Stefan Monnier
2015-09-11  6:54                                     ` Ken Raeburn
2015-09-11  7:22                                       ` Eli Zaretskii
2015-09-11 23:11                                         ` Ken Raeburn
2015-09-12  0:51                                           ` Stefan Monnier
2015-09-12  1:34                                             ` Ken Raeburn
2015-09-15 14:29                                             ` Eli Zaretskii
2015-09-15 16:14                                               ` Stefan Monnier
2015-09-18 14:19                                                 ` Eli Zaretskii
2015-09-21  9:23                                                   ` Ken Raeburn
2015-09-21  9:44                                                     ` Eli Zaretskii
2015-09-23 17:27                                                       ` Ken Raeburn
2015-09-23 18:04                                                         ` martin rudalics
2015-09-23 20:59                                                           ` Ken Raeburn
2015-09-23 19:17                                                         ` Eli Zaretskii
2015-09-24  8:52                                                           ` Ken Raeburn
2015-09-24 18:46                                                             ` Eli Zaretskii
2015-09-24 20:08                                                               ` Ken Raeburn
2015-09-25  6:49                                                                 ` Eli Zaretskii
2015-09-25 12:07                                                                   ` Stefan Monnier
2015-09-26  7:01                                                                   ` Eli Zaretskii
2015-09-25  6:50                                                             ` Eli Zaretskii
2015-09-25 12:09                                                               ` Stefan Monnier
2015-09-25 13:29                                                                 ` Eli Zaretskii
2015-09-25 15:18                                                                   ` Stefan Monnier
2015-09-12  7:30                                           ` Eli Zaretskii
2015-09-11 13:39                                       ` Stefan Monnier
2015-09-11 14:01                                         ` Eli Zaretskii
2015-09-08 13:22                         ` Stefan Monnier
2015-09-08 17:25                           ` Eli Zaretskii
2015-09-08 18:52                             ` Stefan Monnier
2015-09-08 19:08                               ` Eli Zaretskii
2015-09-08 20:37                                 ` Stefan Monnier
2015-09-08 17:36                         ` 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=6e613irc91.fsf@just-testing.permabit.com \
    --to=raeburn@permabit.com \
    --cc=11822@debbugs.gnu.org \
    --cc=eliz@gnu.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).