Subject: bug#20154: closed (Re: bug#20154: 25.0.50; json-encode-string is too slow for large strings)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 07 Apr 2015 13:32:06 +0000

Your bug report

#20154: 25.0.50; json-encode-string is too slow for large strings

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
20154: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20154
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#20154: 25.0.50; json-encode-string is too slow for large strings
From: Dmitry Gutov <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked]
Date: Tue, 07 Apr 2015 16:31:47 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

On 03/23/2015 05:37 PM, Eli Zaretskii wrote:

> Yes, I recommend that.

Thanks.

It appears there's not much that can be done in Lisp. The current speed 
is much better, although it could still use improvement.

Subject: 25.0.50; json-encode-string is too slow for large strings
From: Dmitry Gutov <[email-masked]>
To: [email-masked]
Date: Fri, 20 Mar 2015 16:26:07 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

A 300Kb string takes 0.5s to encode on my machine. Example:

(defvar s (apply #'concat (cl-loop for i from 1 to 30000
                                   collect "0123456789\n")))

(length (json-encode-string s))

For a comparison, the built-in json module in my local Python
installation takes only 2ms to do that for the same string.

This is important for advanced code completion in general, because JSON
is a common transport format, and sending the contents of the current
buffer to the server is a common approach to avoid needlessly saving it
(and running associated hooks, etc).

And in this specific case, our JSON encoding speed is a bottleneck when
working with ycmd, the editor-agnostic code completion daemon extracted
from a popular Vim package:
https://github.com/company-mode/company-mode/issues/325#issuecomment-83120928

I've tried to reimplement this function using `replace-regexp-in-string'
or `re-search-forward' with a temp buffer, to minimize the number of
concatenations and `json-encode-char' calls in the fast case (all
characters are ASCII), but as long as characters that need to be encoded
(such as newlines) still occur throughout the contents of the string,
the speed improvement is nowhere near the acceptable level. Should it be
written in C?

In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.12.2)
 of 2015-03-20 on axl
Repository revision: 8142fc97af742e083fb83e4d0470da59b123a467
Windowing system distributor `The X.Org Foundation', version 11.0.11601901
System Description:	Ubuntu 14.10