From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?S=C3=A9bastien?= Chapuis Newsgroups: gmane.emacs.bugs Subject: bug#31138: Native json slower than json.el Date: Sat, 23 Mar 2019 20:59:46 +0800 Message-ID: References: <87sh806xwa.fsf@chapu.is> <834lkf7ely.fsf@gnu.org> <878t9own1p.fsf@chapu.is> <838t9o4hvl.fsf@gnu.org> <83r2ayovkx.fsf@gnu.org> <83pnqiormy.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="234431"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Ivan Yonchovski , 31138@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 23 14:01:12 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 1h7gGu-000yqs-0m for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Mar 2019 14:01:12 +0100 Original-Received: from localhost ([127.0.0.1]:43222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7gGs-0000xC-SZ for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Mar 2019 09:01:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:50063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7gGl-0000x4-PX for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 09:01:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h7gGk-0007Dw-EH for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 09:01:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41517) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h7gGk-0007Dn-7m for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 09:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h7gGk-0002mG-3B for bug-gnu-emacs@gnu.org; Sat, 23 Mar 2019 09:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?S=C3=A9bastien?= Chapuis Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Mar 2019 13:01: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.155334600710579 (code B ref 31138); Sat, 23 Mar 2019 13:01:02 +0000 Original-Received: (at 31138) by debbugs.gnu.org; 23 Mar 2019 13:00:07 +0000 Original-Received: from localhost ([127.0.0.1]:55061 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h7gFq-0002kJ-H1 for submit@debbugs.gnu.org; Sat, 23 Mar 2019 09:00:06 -0400 Original-Received: from mail-wm1-f51.google.com ([209.85.128.51]:38909) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h7gFo-0002j2-6w for 31138@debbugs.gnu.org; Sat, 23 Mar 2019 09:00:05 -0400 Original-Received: by mail-wm1-f51.google.com with SMTP id a188so4582698wmf.3 for <31138@debbugs.gnu.org>; Sat, 23 Mar 2019 06:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chapu-is.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=O0LCi4XCr29I5F+0Ii17b+1v2jxBqoCCHXIZWa+OyPY=; b=K68donBeSr/1PS9/cggTpQLck8ubt/7AUXW1x0F3LNhzH3QtGlxvgUCDOsUFv3jZAi JcAdfgx5oefqCsgQ8TVh8jRD9nGxpX8Msvqc4ZnkuqTHZHiV/mgm4KhmX/Iv0TGngNxj y0m7g7ZhUgY4iDPAPqdtk1xLJDJIDitBmOn56KUT9mQ9dJwE+go8L3ffNwsc+DbSQmsT 2fcQqW79rc2bWR/XIrSZfS2s7AbD9qeG65NGIekRcPOWLpiC1qdXI+TVMvfX8spD9Bjj bKFzb9//IT6V46s/KdTy3lqpzUzgzHg0hF3ynWe+S08Kjgo6Hd93tnoCXps1OSDbG+ML VQOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=O0LCi4XCr29I5F+0Ii17b+1v2jxBqoCCHXIZWa+OyPY=; b=GogFEz5mZm7qQlG/nPq96ABfHCteWMznFzuq7aeSu0yQAirILWdzTL+sOUVYZsBb7f m7rKJsmPqwEx79ZoN3bIZNcUcckoAb7E+m09PB+7fkhVCeuyc3ciPEkOURkSg6O6+9be VdM4tLZDPWhKBG3A5+9IVMTiTlz8A78F65rv/GZYaF0o9ukMjhiDgghPmk5Ji5FM7FMj ll8U0X4Czthpv8XTSc6fmA3Kpp+zOB7ots7L3qc2tDGTekIrgHoctnsFE61+Ui1yHr9Z 2POTGHHZoQLj8lSrVpxwFJg1kEv90WS9WhNFFkqrVjYirFi2lCY13NzJDfYdIlz3Zu34 5O5A== X-Gm-Message-State: APjAAAXgvyil2ChemoGL+DNjOrhz004PES4XfzhxqKQvxB/K/a/Alwl6 c34ryZscuFqWx+1m3iFgsK8RJOTAL6uZ069GoihAIQ== X-Google-Smtp-Source: APXvYqyrYOr5OC5Xo+zBlFQD9Fxks2kqzLMmEW4JFIpztKZZjst4KxLhSoOjq/9zeKXu5eiKs/1+k0Sn3qUhPVL7O0w= X-Received: by 2002:a1c:98c9:: with SMTP id a192mr39112wme.44.1553345998154; Sat, 23 Mar 2019 05:59:58 -0700 (PDT) In-Reply-To: <83pnqiormy.fsf@gnu.org> 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:156658 Archived-At: Sorry for not being clear, my main concern was the difference when wrapping json-parse-string with with-temp-buffer or not. You are right, I tested with the current master branch and it is faster (emacs -Q): (with-current-buffer "large.json" (benchmark-run 10 (json-parse-string (buffer-string)))) ;;; (1.45898128 10 0.15294547200000003) (with-current-buffer "large.json" (let ((str (buffer-string))) (benchmark-run 10 (with-temp-buffer (json-parse-string str))))) ;;; (0.706171416 10 0.18795709700000002) (with-current-buffer "large.json" (let ((str (buffer-string))) (benchmark-run 10 (with-temp-buffer (json-read-from-string str))))) ;;; (2.476727624 138 1.5660531400000006) I have tested to read the file literally, as you suggested and there is now no difference with or without with-temp-buffer (emacs -Q): (with-current-buffer (find-file-noselect "large.json" nil t) (benchmark-run 10 (json-parse-string (buffer-string)))) ;;; (0.7011264119999999 10 0.118889765) (with-current-buffer (find-file-noselect "large.json" nil t) (let ((str (buffer-string))) (benchmark-run 10 (with-temp-buffer (json-parse-string str))))) ;;; (0.7159130309999999 10 0.15112133999999997) For the context, with lsp-mode, we have users complaining about performance of json-parse-string [1]. Some have found out that the function is way faster with emacs -Q but it is "dead slow" with their Spacemacs setup. In lsp-mode, we are reading child process output by calling `make-process` with `:coding 'no-conversion`, I think it has the same behavior than reading a file "literally" ? Is there anything else we could do to improve the performance from reading the process output ? Now the problem is how can we have the same performance with a regular emacs setup than with emacs -Q ? With my emacs setup, I have this result: (with-current-buffer (find-file-noselect "large.json" nil t) (benchmark-run 10 (json-parse-string (buffer-string)))) ;;; (1.515018996 10 0.5256668049999996) (with-current-buffer (find-file-noselect "large.json" nil t) (let ((str (buffer-string))) (benchmark-run 10 (with-temp-buffer (json-parse-string str))))) ;;; (1.156755376 10 0.5596599300000001) This is almost 2x slower than with emacs -Q. Note that there is still a difference with and without `with-temp-buffer`. What can we do to reach emacs -Q performance ? Thanks for your time, Sebastien Chapuis [1] https://github.com/emacs-lsp/lsp-mode/issues/210#issuecomment-471314904 Le sam. 23 mars 2019 =C3=A0 17:40, Eli Zaretskii a =C3=A9cri= t : > > > Date: Sat, 23 Mar 2019 10:15:26 +0200 > > From: Eli Zaretskii > > Cc: yyoncho@gmail.com, 31138@debbugs.gnu.org > > > > 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). > > I've just tried on another system, and there I get the native JSON > support 3 times faster than json.el.