Subject: minor jsonrpc optimisation suggestions

From: Mattias Engdegård <[email-masked]>
Date: Mon, 1 Sep 2025 20:58:50 +0200

Emacs's built-in JSON parser happily accepts encoded unibyte strings and buffers as input because JSON is specified at byte level. This means that any effort to decode the input to multibyte first is wasted. (This overhead is quite measurable in general.)

For jsonrpc this means that for good performance, make sure the process buffer is unibyte and set the process coding system to something like `binary`. The filter function will then be passed unibyte strings. (The `position-bytes` and `byte-to-position` calls become identity and can be eliminated.)

This should apply to both the old (libjansson) and new JSON parsers. The old json.el parser (json-read) doesn't cope well with unibyte input (unless it's all-ASCII, of course), so for the masochists you may want some compatibility code.

Here is a proof-of-concept patch, largely untested and untimed (well, it compiles and passes the tests).