Subject: bug#32728: bug#32729: Xemacs 23 times as fast as GNU Emacs

From: Eli Zaretskii <[email-masked]>
Date: Mon, 14 Oct 2019 12:15:09 +0300

> From: Lars Ingebrigtsen <[email-masked]>
> Cc: [email-masked],  [email-masked],
>   [email-masked],  [email-masked]
> Date: Mon, 14 Oct 2019 10:36:11 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > I don't understand what would trigger these callbacks, and how do you
> > specify the region in advance, without knowing what will be inserted.
> 
> accept_process_output inserts the data into the buffer and then calls
> the callback with the region in question.  Well,
> read_and_dispose_of_process_output, I guess...

Filter functions are called even if the Lisp program never calls
accept-process-output, so your proposal doesn't seem to be equivalent
to what we have now, right?

OTOH, if one has to call accept-process-output, then why do we need
callbacks?  Just extend accept-process-output to call a function with
the received output.  No?

> > Without understanding this, I don't think I see the utility, and most
> > important: why this would be faster.
> 
> It would avoid creating (and garbaging) the strings.

I'm not sure I see how.

The way it works now is that we get the process output as a C string;
we then decode it and make a Lisp string from the result of decoding;
and then we invoke the filter with that Lisp string.  (If the filter
is nil, we invoke internal-default-process-filter instead, but it
still gets the text as a string.)

Which part(s) of this will be avoided under your proposal?

> > Btw, unlike what I originally implied, the default filter also
> > receives a Lisp string, so the question why by default reading dd
> > output is so much faster than when you define a non-default filter
> > function still stands.
> 
> Oh!  That is curious indeed.  Are the Lisp_Object strings somehow
> ... special here when they never leave C land?

No, I don't think so.

> The speed differential is completely repeatable...  hm...  Is the
> only difference that gc isn't given a chance to run in the
> non-filter case?

You could test that hypothesis by setting gc-cons-threshold to a very
high value.

Bottom line: I think we must understand better what takes the time in
your last test case, before we discuss solutions.  I'd start by
profiling that with "M-x profiler-start".