From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov 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:26:07 +0200 Message-ID: <86twxf68zk.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1426861646 9710 80.91.229.3 (20 Mar 2015 14:27:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 20 Mar 2015 14:27:26 +0000 (UTC) To: 20154@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 20 15:27:15 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 1YYxtI-0007vk-4N for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Mar 2015 15:27:12 +0100 Original-Received: from localhost ([::1]:44097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYxtH-00075h-96 for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Mar 2015 10:27:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYxtC-00074D-7V for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:27:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYxt8-0001rd-4L for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:27:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41202) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYxt8-0001rZ-16 for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YYxt7-0007In-RJ for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:27:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Mar 2015 14:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 20154 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.142686159528031 (code B ref -1); Fri, 20 Mar 2015 14:27:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Mar 2015 14:26:35 +0000 Original-Received: from localhost ([127.0.0.1]:59210 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYxsg-0007I1-NK for submit@debbugs.gnu.org; Fri, 20 Mar 2015 10:26:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37766) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YYxsf-0007Hp-2t for submit@debbugs.gnu.org; Fri, 20 Mar 2015 10:26:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYxsY-0001nd-L4 for submit@debbugs.gnu.org; Fri, 20 Mar 2015 10:26:27 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:40474) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYxsY-0001nZ-IR for submit@debbugs.gnu.org; Fri, 20 Mar 2015 10:26:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYxsX-0006s0-3w for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:26:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYxsP-0001mR-Qi for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:26:25 -0400 Original-Received: from mail-wg0-x22c.google.com ([2a00:1450:400c:c00::22c]:33796) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYxsP-0001m7-JT for bug-gnu-emacs@gnu.org; Fri, 20 Mar 2015 10:26:17 -0400 Original-Received: by wggv3 with SMTP id v3so90849697wgg.1 for ; Fri, 20 Mar 2015 07:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:mime-version:content-type; bh=rbArsYm15+hrChPK5LGAz/BhBJuSPCOyJ6hmmF2uhJI=; b=b1ZGtuG7zHI4PbKiXadhlFtGPIj+4GqdPFLoTP8iD/bkrLUAJmux0aUNcHwi0g01bm /z1ENHiDU8HW4M2D/KnpHVhKLj8Jcq3zwvTjK7L3dNZX0bCJ6nm+V+hm/KFRxD1hb5iN doUpFfFoevYfDNeAf3P7l0CzKi+3VA7tsG6x3XL10WZa+RkpL9FoeZa7k/QJGZtczVlc L968DC9nLa20OMdSDx/m4EplVEPRZbOQnCewQHtxL+bt/vOgWib+A9ZmzPntUqLqD3bd z8SAbHKoLFoemv+Bf0JztNqQnq9E8LlDi9lTAq/kFcbjconhBNrikZ6Bm3c6IGk9AZ/q XF+g== X-Received: by 10.180.202.228 with SMTP id kl4mr5681314wic.66.1426861576108; Fri, 20 Mar 2015 07:26:16 -0700 (PDT) Original-Received: from axl ([82.102.93.54]) by mx.google.com with ESMTPSA id z13sm6570117wjr.44.2015.03.20.07.26.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Mar 2015 07:26:15 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:100694 Archived-At: 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