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 18:02:57 +0200 Message-ID: <83wq2bveq6.fsf@gnu.org> References: <86twxf68zk.fsf@yandex.ru> <83384zwxdx.fsf@gnu.org> <550C3218.4000903@yandex.ru> <831tkjww0y.fsf@gnu.org> <550C3AB9.7020403@yandex.ru> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1426867466 14681 80.91.229.3 (20 Mar 2015 16:04:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 20 Mar 2015 16:04:26 +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 17:04:14 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 1YYzP7-0004yV-To for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Mar 2015 17:04:10 +0100 Original-Received: from localhost ([::1]:44618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYzP7-0000EO-8x for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Mar 2015 12:04:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYzP3-0000EI-Fr for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 12:04:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYzP0-0006e0-8W for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 12:04:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYzP0-0006dw-4w for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 12:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YYzOz-0001Du-Sb for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 12:04: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 16:04: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.14268673894637 (code B ref 20154); Fri, 20 Mar 2015 16:04:01 +0000 Original-Received: (at 20154) by debbugs.gnu.org; 20 Mar 2015 16:03:09 +0000 Original-Received: from localhost ([127.0.0.1]:59295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYzO8-0001Ci-TQ for submit@debbugs.gnu.org; Fri, 20 Mar 2015 12:03:09 -0400 Original-Received: from mtaout28.012.net.il ([80.179.55.184]:51390) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYzO6-0001CC-9C for 20154@debbugs.gnu.org; Fri, 20 Mar 2015 12:03:07 -0400 Original-Received: from conversion-daemon.mtaout28.012.net.il by mtaout28.012.net.il (HyperSendmail v2007.08) id <0NLI00100PSXB600@mtaout28.012.net.il> for 20154@debbugs.gnu.org; Fri, 20 Mar 2015 18:01:35 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout28.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NLI00DV6PUNPVA0@mtaout28.012.net.il>; Fri, 20 Mar 2015 18:01:35 +0200 (IST) In-reply-to: <550C3AB9.7020403@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:100707 Archived-At: > Date: Fri, 20 Mar 2015 17:20:25 +0200 > From: Dmitry Gutov > CC: 20154@debbugs.gnu.org > > On 03/20/2015 05:03 PM, Eli Zaretskii wrote: > > > Yes, I could. What's your point, though? > > That if asking the question takes the same time as doing the profiling > yourself, the latter would be more efficient. I don't really mind, just > puzzled. I have other things on my plate while I read email. If my advice bothers you, I can shut up in the future. > > json-encode-char and mapconcat take most of the time, so it seems. > > So it does. But here's an alternative implementation I tried: > > (defun json-encode-big-string (str) > (with-temp-buffer > (insert str) > (goto-char (point-min)) > (while (re-search-forward "[\"\\/\b\f\b\r\t]\\|[^ -~]" nil t) > (replace-match (json-encode-char (char-after (match-beginning 0))) > t t)) > (format "\"%s\"" (buffer-string)))) > > It takes 0.15s here, which is still too long. I suggest to rewrite json-encode-char, it does a lot of unnecessary stuff, starting with the call to encode-char (which was needed in Emacs 22 and before, but no more). The call to rassoc is also redundant, since you already have that covered in your regexp.