Subject: Re: bug#58302: 29.0.50; browse-url-emacs is extremely slow (and I think always has been?)

From: Phil Sainty <[email-masked]>
Date: Thu, 13 Oct 2022 00:28:20 +1300

On 2022-10-13 00:03, Lars Ingebrigtsen wrote:
> I think the conclusion here is that using the file-name-handler-alist
> stuff for this is the absolutely pessimal way to implement
> `browse-url-emacs'.
> 
> It should be pretty easy to rewrite browse-url-emacs to just call
> `url-retrieve-synchronously' explicitly, and then display the resulting
> data -- and it should be much, much faster.

Undoubtedly so; but making the existing approach more efficient might
also bring the same benefits to other functionality?

E.g.:

(url-handler-mode 1)

(trace-function 'url-retrieve-synchronously "*trace-output*"
		(lambda () (format " [%s]" url-request-method)))

(find-file "http://www.example.com")

======================================================================
1 -> (url-retrieve-synchronously #s(url "http" nil nil "www.example.com" 
nil "" nil nil t nil t t)) [OPTIONS]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[OPTIONS]
======================================================================
1 -> (url-retrieve-synchronously #s(url "http" nil nil "www.example.com" 
nil "" nil nil t nil t nil)) [HEAD]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[HEAD]
======================================================================
1 -> (url-retrieve-synchronously #s(url "http" nil nil "www.example.com" 
nil "" nil nil t nil t t)) [OPTIONS]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[OPTIONS]
======================================================================
1 -> (url-retrieve-synchronously #s(url "http" nil nil "www.example.com" 
nil "" nil nil t nil t nil)) [HEAD]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[HEAD]
======================================================================
1 -> (url-retrieve-synchronously "http://www.example.com") [nil]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[nil]
======================================================================
1 -> (url-retrieve-synchronously #s(url "http" nil nil "www.example.com" 
nil "" nil nil t nil t t)) [HEAD]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[HEAD]
======================================================================
1 -> (url-retrieve-synchronously #s(url "http" nil nil "www.example.com" 
nil "" nil nil t nil t t)) [HEAD]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[HEAD]
======================================================================
1 -> (url-retrieve-synchronously #s(url "http" nil nil "www.example.com" 
nil "" nil nil t nil t t)) [HEAD]
1 <- url-retrieve-synchronously: #<buffer  *http www.example.com:80*> 
[HEAD]