From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#20154: 25.0.50; json-encode-string is too slow for large strings Date: Fri, 20 Mar 2015 16:34:34 +0200 Message-ID: <83384zwxdx.fsf@gnu.org> References: <86twxf68zk.fsf@yandex.ru> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1426862129 17866 80.91.229.3 (20 Mar 2015 14:35:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 20 Mar 2015 14:35:29 +0000 (UTC) Cc: 20154@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 20 15:35:19 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YYy14-00062I-Nl for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Mar 2015 15:35:14 +0100 Original-Received: from localhost ([::1]:44156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYy14-00068U-21 for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Mar 2015 10:35:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYy0w-00063a-N0 for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:35:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYy0s-0004HG-I2 for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:35:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYy0s-0004H4-FT for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YYy0r-0007Wu-Sm for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Mar 2015 14:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20154 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20154-submit@debbugs.gnu.org id=B20154.142686208728918 (code B ref 20154); Fri, 20 Mar 2015 14:35:01 +0000 Original-Received: (at 20154) by debbugs.gnu.org; 20 Mar 2015 14:34:47 +0000 Original-Received: from localhost ([127.0.0.1]:59247 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYy0c-0007WM-Td for submit@debbugs.gnu.org; Fri, 20 Mar 2015 10:34:47 -0400 Original-Received: from mtaout23.012.net.il ([80.179.55.175]:52946) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYy0Z-0007W7-JT for 20154@debbugs.gnu.org; Fri, 20 Mar 2015 10:34:44 -0400 Original-Received: from conversion-daemon.a-mtaout23.012.net.il by a-mtaout23.012.net.il (HyperSendmail v2007.08) id <0NLI00600LQGZ600@a-mtaout23.012.net.il> for 20154@debbugs.gnu.org; Fri, 20 Mar 2015 16:34:36 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout23.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NLI00676LTOY710@a-mtaout23.012.net.il>; Fri, 20 Mar 2015 16:34:36 +0200 (IST) In-reply-to: <86twxf68zk.fsf@yandex.ru> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:100699 Archived-At: > From: Dmitry Gutov > 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? I suggest to start with a detailed profile of the current implementation, because only then we will be able to talk intelligently about what part(s) need(s) to be sped up. Thanks.