4

When start a command asynchronously, using (start-process ...), the output is added to the buffer 3-5 times more slowly than if I had used (async-shell-command ...). I don't have any output filters, I need start process because I need to be notified when the process exits.

The issue seems to have been raised here:

https://lists.gnu.org/archive/html//emacs-devel/2008-07/msg01436.html

but apparently it was never resolved.

What is causing the significant slowdown in output (basically I just want to dump all the output to a buffer and be notified when that is done). Are there output filters running even though I haven't specified any? Is this a matter of increasing some buffer size?

Edit: There's a related question here and an apparent patch available. Size of process output sent to filter functions

1

Emacs is much slower than a plain text terminal to display a buffer. This is why

(start-process "catxdisp" (current-buffer) "time" "cat" (expand-file-name "src/xdisp.c" source-directory))

takes much more time than e.g.

;; -*- lexical-binding: t; -*-
(let ((buf (get-buffer-create "catxdisp")))
  (set-process-sentinel
   (start-process "catxdisp" buf "time" "cat" (expand-file-name "src/xdisp.c" source-directory))
   (lambda (_ _)
     (display-buffer buf))))

(the process sentinel is a way to display the buffer only when the process has finished.) On my system the former (which displays the output continuously) takes about 11 seconds while the latter (which only displays the buffer with the output once it's all done) takes about 2 seconds.

  • Don't you need something like (lambda (p e) (when (= 0 (process-exit-status p)) (display-buffer buf)) to ensure that the process actually finishes before displaying the buf? – lawlist Jul 9 '15 at 22:31
  • Thanks, but this doesn't answer the question at all. There's no inherent reason why emacs should have to take longer than a terminal to display the stdout of a subprocess. Also, you're not even offering an alternative. See my edit about the related question and potential bug-fix – erjoalgo Jul 10 '15 at 0:11
  • @lawlist IIUC every invokation of the process sentinel means the process has stopped (normally, or abnormally). – YoungFrog Jul 10 '15 at 9:21
  • @user84207 I don't think this "doesn't answer the question at all", but I certainly think it is incomplete. Since you gave no recipe, I tried to guess, and my (naive) guess was that the slowdown you mentionned is mostly related to emacs trying to display the output as it arrives. Maybe you're really asking "why does it still take 2 seconds in the second example ?" and that is a very valid question, but I don't have an answer (beyond what you linked to). – YoungFrog Jul 10 '15 at 9:34
  • yeah. thanks for running your test though, it's definitely the problem I'm having. but consider that the terminal also needs to display the output as it arrives, and the terminal is just another program like emacs, invoking a process and reading its output. So this is most likely a bug in emacs, as the discussion in the other question shows. – erjoalgo Jul 10 '15 at 11:46
0

I was actually having an unrelated problem with video drivers, causing the machine's performance in general to crawl to a halt. Although the start process is slightly slower, it is probably not 3-5x slower as I originally stated. So I do not think this is a major issue, it was probably confusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.