GNU bug report logs - #79361
minor jsonrpc optimisation suggestions

Previous Next

Package: emacs;

Reported by: Mattias Engdegård <mattias.engdegard <at> gmail.com>

Date: Mon, 1 Sep 2025 19:00:02 UTC

Severity: normal

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Emacs Bug Report <bug-gnu-emacs <at> gnu.org>
Cc: João Távora <joaotavora <at> gmail.com>
Subject: minor jsonrpc optimisation suggestions
Date: Mon, 1 Sep 2025 20:58:50 +0200
[Message part 1 (text/plain, inline)]
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).

[jsonrpc.diff (application/octet-stream, attachment)]

This bug report was last modified today.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.