Subject: Re: bug#18626: 24.3.94; communication with subprocess is slow

From: Stephen Leake <[email-masked]>
Date: Sun, 05 Oct 2014 08:41:08 -0500

Stephen Leake <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>> Can you present similar timings from some Posix platform for
>> comparison?
>
> On Debian wheezy, with emacs 24.3.94:
>
> $ cd /tmp
> $ time cat < /home/Projects/emacs/emacs-24.3.94/src/xdisp.c > xdisp.c
> real	0m0.007s
> user	0m0.000s
> sys	0m0.004s
>
>
> (find-file "emacs-24.3.94/src/xdisp.c")
> (pipe-torture "cat.exe")
> 1.556597
>
> much faster than Windows, but still slow relative to plain file IO.
>
> (pipe-torture "debug.exe" "4096")
>
> This dies, because "debug.exe" exits early. It turns out that Emacs is
> sending one line of the buffer at a time. I have not yet tried to figure
> out why that doesn't happen on Windows.

I rewrote debug.adb to handle this case by exiting when the total bytes
read equals the file size:

with Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.OS_Lib;
procedure Debug_Counted
is
   use GNAT.OS_Lib;

   Chunk     : constant Integer := Integer'Value (Ada.Command_Line.Argument (1));
   File_Size : constant Integer := Integer'Value (Ada.Command_Line.Argument (2));

   File             : constant File_Descriptor := GNAT.OS_Lib.Standin;
   Read_Bytes       : Integer;
   Total_Read_Bytes : Integer                  := 0;
   Text             : aliased String (1 .. Chunk);
   Short_Count      : Integer                  := 0;
   Count            : Integer                  := 0;
begin
   loop
      Read_Bytes := Read (File, Text'Address, Chunk);
      Total_Read_Bytes := Total_Read_Bytes + Read_Bytes;
      if Read_Bytes < Chunk then
         Short_Count := Short_Count + 1;
      else
         Count := Count + 1;
      end if;
      exit when Total_Read_Bytes >= File_Size;
   end loop;
   Put_Line ("Short_Count => " & Integer'Image (Short_Count) & " Count => " & Integer'Image (Count));
end Debug_Counted;

(find-file "xdisp.c")
(pipe-torture
"/home/Projects/org.emacs.ada-mode.stephe-1/build/wisi/debug_counted"
"4096" "974230")

0.344027

This is comparable to the time on Windows with a large buffer in the
subprocess. So apparently it is not using the same delay in
send_process. Or the IO system is providing a large buffer.

-- 
-- Stephe