[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31138: Native json slower than json.el

From: Sebastien Chapuis
Subject: bug#31138: Native json slower than json.el
Date: Sun, 15 Apr 2018 16:40:18 +0200
User-agent: mu4e 0.9.19; emacs 27.0.50

Eli Zaretskii writes:

> I'm surprised that the slowdown due to the conversion is so large,
> though.  It doesn't feel right, even with a 4MB string.

I've digged a bit to know why it is so slow, and I've found that if I'm
wrapping `json-parse-string` with a `with-temp-buffer`, it is now way

results of benchmark-run with a string of 4043212 characters
(with-temp-buffer (json-parse-string str)):
(0.814315554 1 0.11941178500000005)

(json-parse-string str):
(11.542233167 1 0.14954429599999997)

(with-temp-buffer (json-read-from-string str)):
(5.9781185610000005 29 4.967349412000001)

(json-read-from-string str):
(5.601267 24 4.723292248000001)

Any idea why ? The current (buffer-size) is 1063954, if it is relevant.

> Yes, it's necessary, because the input string may include raw bytes,
> which will crash Emacs if not handled properly.

The Jansson documentation guarantee that the strings returned
from the library are always UTF-8 encoded [1].
By knowing that guarantee, is it possible to reconsider the use of
code_convert_string ?
Encoding a string to UTF-8 which is already UTF-8 encoded seems

[1] https://jansson.readthedocs.io/en/2.11/apiref.html#c.json_string_value

Sebastien Chapuis

reply via email to

[Prev in Thread] Current Thread [Next in Thread]