unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20154: 25.0.50; json-encode-string is too slow for large strings
@ 2015-03-20 14:26 Dmitry Gutov
  2015-03-20 14:34 ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Dmitry Gutov @ 2015-03-20 14:26 UTC (permalink / raw)
  To: 20154

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





^ permalink raw reply	[flat|nested] 45+ messages in thread

end of thread, other threads:[~2015-04-20 23:11 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-20 14:26 bug#20154: 25.0.50; json-encode-string is too slow for large strings Dmitry Gutov
2015-03-20 14:34 ` Eli Zaretskii
2015-03-20 14:43   ` Dmitry Gutov
2015-03-20 15:03     ` Eli Zaretskii
2015-03-20 15:20       ` Dmitry Gutov
2015-03-20 16:02         ` Eli Zaretskii
2015-03-20 16:21           ` Dmitry Gutov
2015-03-20 16:44             ` Eli Zaretskii
2015-03-20 16:52               ` Dmitry Gutov
2015-03-20 17:44                 ` Eli Zaretskii
2015-03-20 18:42                   ` Dmitry Gutov
2015-03-20 21:14                     ` Eli Zaretskii
2015-03-20 22:02                       ` Dmitry Gutov
2015-03-21  7:58                         ` Eli Zaretskii
2015-03-21  8:12                           ` Eli Zaretskii
2015-03-21 20:00                           ` Dmitry Gutov
2015-03-21 20:25                             ` Eli Zaretskii
2015-03-21 21:26                               ` Dmitry Gutov
2015-03-22 17:31                                 ` Eli Zaretskii
2015-03-22 18:13                                   ` Dmitry Gutov
2015-03-22 18:26                                   ` Dmitry Gutov
2015-03-22 18:32                                     ` Eli Zaretskii
2015-03-22 19:03                                       ` Dmitry Gutov
2015-03-21 21:05                             ` Drew Adams
2015-03-21 21:32                               ` Dmitry Gutov
2015-04-20 22:20                         ` Ted Zlatanov
2015-04-20 22:41                           ` Dmitry Gutov
2015-04-20 23:11                             ` Ted Zlatanov
2015-03-20 22:26                       ` Dmitry Gutov
2015-03-21  8:07                         ` Eli Zaretskii
2015-03-21 21:09                           ` Dmitry Gutov
2015-03-21 22:20                             ` Ivan Shmakov
2015-03-21 23:36                               ` Dmitry Gutov
2015-03-22 14:52                             ` Dmitry Gutov
2015-03-22 16:15                               ` Ivan Shmakov
2015-03-22 16:47                                 ` Dmitry Gutov
2015-03-22 17:43                                   ` Eli Zaretskii
2015-03-22 19:15                                   ` Ivan Shmakov
2015-03-22 16:51                                 ` Eli Zaretskii
2015-03-22 18:22                                 ` Glenn Morris
2015-03-22 16:50                               ` Eli Zaretskii
2015-03-22 17:10                                 ` Dmitry Gutov
2015-03-22 22:57           ` Dmitry Gutov
2015-03-23 15:37             ` Eli Zaretskii
2015-04-07 13:31               ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).