From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#31138: Native json slower than json.el Date: Sat, 23 Mar 2019 10:15:26 +0200 Message-ID: <83r2ayovkx.fsf@gnu.org> References: <87sh806xwa.fsf@chapu.is> <834lkf7ely.fsf@gnu.org> <878t9own1p.fsf@chapu.is> <838t9o4hvl.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="195524"; mail-complaints-to="usenet@blaine.gmane.org" Cc: yyoncho@gmail.com, 31138@debbugs.gnu.org To: =?UTF-8?Q?S=C3=A9bastien?= Chapuis Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 23 09:27:54 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7c0Q-000oir-3W for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Mar 2019 09:27:54 +0100 Original-Received: from localhost ([127.0.0.1]:40369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7c0P-0003ix-1c for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Mar 2019 04:27:53 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7c09-0003gI-K2 for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 04:27:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h7box-0001ln-NL for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 04:16:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41447) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h7bow-0001lN-Lk for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 04:16:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h7bow-0000IT-Db for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 04:16: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: Sat, 23 Mar 2019 08:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31138 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 31138-submit@debbugs.gnu.org id=B31138.15533289391108 (code B ref 31138); Sat, 23 Mar 2019 08:16:02 +0000 Original-Received: (at 31138) by debbugs.gnu.org; 23 Mar 2019 08:15:39 +0000 Original-Received: from localhost ([127.0.0.1]:54991 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h7boY-0000Ho-Lz for submit@debbugs.gnu.org; Sat, 23 Mar 2019 04:15:39 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:53927) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h7boU-0000Ha-RQ for 31138@debbugs.gnu.org; Sat, 23 Mar 2019 04:15:37 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:60301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7boP-0001d3-Iq; Sat, 23 Mar 2019 04:15:29 -0400 Original-Received: from [176.228.60.248] (port=4587 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1h7boO-0000GV-UJ; Sat, 23 Mar 2019 04:15:29 -0400 In-reply-to: (message from =?UTF-8?Q?S=C3=A9bastien?= Chapuis on Sat, 23 Mar 2019 09:59:23 +0800) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:156652 Archived-At: > From: Sébastien Chapuis > Date: Sat, 23 Mar 2019 09:59:23 +0800 > Cc: 31138@debbugs.gnu.org, yyoncho@gmail.com > > I tried to find the cause of this but still without any success. > Here is a reproducible case: > > You can download the json file at: > https://gist.githubusercontent.com/yyoncho/dec968b69185305ed02741e18b27a82d/raw/334b0a51bc52cc3c98edb8ff4bccb5fc4531842b/large.json > > Open the file with `emacs -Q large.json`. > Switch to the scratch buffer and run: > > ``` > (with-current-buffer "large.json" > (benchmark-run 10 (json-parse-string (buffer-string)))) > ;;; (2.5371836119999998 10 0.111044641) > > (with-current-buffer "large.json" > (let ((str (buffer-string))) > (benchmark-run 10 (with-temp-buffer (json-parse-string str))))) > ;;; (1.510604359 10 0.13192760000000003) > > (with-current-buffer "large.json" > (let ((str (buffer-string))) > (benchmark-run 10 (with-temp-buffer (json-read-from-string str))))) > ;;; (1.970248228 114 1.058150570000001) > ``` Is this with the latest Emacs master branch? If not, can you try the latest master? FWIW, I cannot reproduce your results with the current master. I get the following times: (with-current-buffer "large.json" (let ((str (buffer-string))) (benchmark-run 10 (with-temp-buffer (json-parse-string str))))) (0.78125 10 0.15625) (with-current-buffer "large.json" (benchmark-run 10 (progn (goto-char (point-min)) (json-parse-buffer)))) (0.890625 10 0.140625) (with-current-buffer "large.json" (let ((str (buffer-string))) (benchmark-run 10 (with-temp-buffer (json-read-from-string str))))) (2.84375 126 1.21875) So on my system the native JSON support does this job about 4 times faster than the Lisp implementation. I see the same ratio of 4 consistently in both optimized and unoptimized builds of Emacs (the above numbers are from an optimized build). Please note that in my experiments I visited the large.json file with find-file-literally, not with find-file. In my testing, I didn't see any difference in timings either way, but visiting literally is more correct for the real-life use cases.