GNU bug report logs - #20154
25.0.50; json-encode-string is too slow for large strings

Previous Next

Package: emacs;

Reported by: Dmitry Gutov <dgutov <at> yandex.ru>

Date: Fri, 20 Mar 2015 14:27:01 UTC

Severity: normal

Found in version 25.0.50

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Dmitry Gutov <dgutov <at> yandex.ru>
Subject: bug#20154: closed (Re: bug#20154: 25.0.50; json-encode-string is
 too slow for large strings)
Date: Tue, 07 Apr 2015 13:32:06 +0000
[Message part 1 (text/plain, inline)]
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 20154 <at> debbugs.gnu.org.

-- 
20154: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20154
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 20154-done <at> debbugs.gnu.org
Subject: Re: bug#20154: 25.0.50; json-encode-string is too slow for
 large strings
Date: Tue, 07 Apr 2015 16:31:47 +0300
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.

[Message part 3 (message/rfc822, inline)]
From: Dmitry Gutov <dgutov <at> yandex.ru>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; json-encode-string is too slow for large strings
Date: Fri, 20 Mar 2015 16:26:07 +0200
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



This bug report was last modified 10 years and 38 days ago.

Previous Next


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