Subject: bug#78773: [PATCH] Speedup url-retrieve-synchronously for low-latency connections

From: Robert Pluim <[email-masked]>
Date: Fri, 13 Jun 2025 10:58:07 +0200

>>>>> On Thu, 12 Jun 2025 13:54:01 -0700, Steven Allen <[email-masked]> said:

    Steven> Ok, I think I've figured it out. We loop twice and wait on a timeout
    Steven> (READ_OUTPUT_DELAY_INCREMENT) the second loop because we're already done
    Steven> reading.

    Steven> The first time through, we hit the following, recording that we've
    Steven> gotten some output:

    Steven>   https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/src/process.c?h=81a3e4e51167be51c63eae682331210bc62f7280#n5974

    Steven> We hit the following, setting our timeout to READ_OUTPUT_DELAY_INCREMENT:

    Steven>   https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/src/process.c?h=81a3e4e51167be51c63eae682331210bc62f7280#n5679

    Steven> Then we hit the select call and wait the full timeout (nothing to read)
    Steven> and we finally exit here (because our timeout has passed):

    Steven>   https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/src/process.c?h=81a3e4e51167be51c63eae682331210bc62f7280#n5832

    Steven> ***

    Steven> I think what we need to do is modify:

    Steven>   https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/src/process.c?h=81a3e4e51167be51c63eae682331210bc62f7280#n5978

    Steven> from

    Steven>     		  if (wait_proc == XPROCESS (proc))
    Steven> 		    wait = MINIMUM;

    Steven> to

    Steven>     		  if (!wait_proc || wait_proc == XPROCESS (proc))
    Steven> 		    wait = MINIMUM;

    Steven> So that we set the timeout to 0 here:

    Steven>   https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/src/process.c?h=81a3e4e51167be51c63eae682331210bc62f7280#n5439

    Steven> And exit early.

That analysis looks correct to me. It works for the original test
case, at least.

Iʼm wondering why weʼre setting the timeout to zero and calling
`pselect' again, which means recomputing the wait set again, if I
havenʼt gotten lost in the twisty maze of ifʼs and global variables
😀. Weʼve got input, why canʼt we just `break'? There might be some
work we donʼt do, but that will get done the next time
`wait_reading_process_output' is called.

Robert
--