Subject: bug#79361: minor jsonrpc optimisation suggestions

From: Eli Zaretskii <[email-masked]>
Date: Tue, 02 Sep 2025 14:10:19 +0300

> Cc: João Távora <[email-masked]>
> From: Mattias Engdegård <[email-masked]>
> Date: Mon, 1 Sep 2025 20:58:50 +0200
> 
> --- a/lisp/jsonrpc.el
> +++ b/lisp/jsonrpc.el
> @@ -548,11 +548,13 @@ initialize-instance
>      (set-process-buffer proc (get-buffer-create (format " *%s output*" name)))
>      (set-process-filter proc #'jsonrpc--process-filter)
>      (set-process-sentinel proc #'jsonrpc--process-sentinel)
> +    (set-process-coding-system proc 'binary 'binary)

Why not do this at make-process time?

>      (with-current-buffer (process-buffer proc)
>        (buffer-disable-undo)
>        (set-marker (process-mark proc) (point-min))
>        (let ((inhibit-read-only t))
>          (erase-buffer))
> +      (set-buffer-multibyte nil)

I would move this to make it the first thing we do in the buffer.

> +        ;; `json-read' requires decoded input.
> +        (json-read-from-string (decode-coding-string (buffer-string) 'utf-8)))))

Should be utf-8-unix, I believe, since JSON requires a literal \n as a
newline convention.

And yes, it would be nice to have timings.