From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Sebastien Chapuis Newsgroups: gmane.emacs.bugs Subject: bug#31138: Native json slower than json.el Date: Sun, 15 Apr 2018 16:40:18 +0200 Message-ID: <878t9own1p.fsf@chapu.is> References: <87sh806xwa.fsf@chapu.is> <834lkf7ely.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1523803147 17925 195.159.176.226 (15 Apr 2018 14:39:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 15 Apr 2018 14:39:07 +0000 (UTC) User-Agent: mu4e 0.9.19; emacs 27.0.50 Cc: 31138@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Apr 15 16:39:02 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f7io2-0004X4-1S for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Apr 2018 16:39:02 +0200 Original-Received: from localhost ([::1]:47420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7iq8-0002dQ-Nh for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Apr 2018 10:41:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f7iq1-0002co-SR for bug-gnu-emacs@gnu.org; Sun, 15 Apr 2018 10:41:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f7ipy-0001fE-On for bug-gnu-emacs@gnu.org; Sun, 15 Apr 2018 10:41:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46386) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f7ipy-0001f3-KW for bug-gnu-emacs@gnu.org; Sun, 15 Apr 2018 10:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1f7ipy-0007Tp-Au for bug-gnu-emacs@gnu.org; Sun, 15 Apr 2018 10:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sebastien Chapuis Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Apr 2018 14:41: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: Original-Received: via spool by 31138-submit@debbugs.gnu.org id=B31138.152380322928672 (code B ref 31138); Sun, 15 Apr 2018 14:41:02 +0000 Original-Received: (at 31138) by debbugs.gnu.org; 15 Apr 2018 14:40:29 +0000 Original-Received: from localhost ([127.0.0.1]:54283 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f7ipQ-0007SO-SO for submit@debbugs.gnu.org; Sun, 15 Apr 2018 10:40:29 -0400 Original-Received: from mail-wr0-f177.google.com ([209.85.128.177]:38066) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f7ipP-0007S3-1N for 31138@debbugs.gnu.org; Sun, 15 Apr 2018 10:40:27 -0400 Original-Received: by mail-wr0-f177.google.com with SMTP id h3so6571434wrh.5 for <31138@debbugs.gnu.org>; Sun, 15 Apr 2018 07:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chapu-is.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=L2nyWd5KmzqD0k+vqeHP3cbCYG9S4o+2GCgwR0Nu/z8=; b=w/T/25NZuT4YDvt+YaYzQCrW1QTBgLjrSRwMm74FLzu/usPD78vtLk9WPZD3QAn83S ss0tSk2/GYuFpk8ZhFqkRz+Qx6AShLi7pM2UYGX4pbAY1ectGXcijsjoAh0XZOW/yEdK OCco/A//pCySpXCtzNJMtiMJoUuZVvnS8wfAfjNfqomeqIzr/5SRMEC9v9+9RoGyTeAa O6pWo8foz7eXk3DKjTw6srn5h0J/t8rci119IP1aWi3Gq6fkjMnqbbbZt/Eu+aKEUyJU hxSe5q1v/0d2ZsvMt9SMldtDkb4/GxiEjbGjwmKvQzKOjTmgMHRX/uovl7w8htHO4rJZ VLzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=L2nyWd5KmzqD0k+vqeHP3cbCYG9S4o+2GCgwR0Nu/z8=; b=nnGVX/d7+fuMNJwIzSFnGxsIWDchSbLk1MoycG4y7BzKp7YlgfmCCsrvzStgaFniKb 0n6E1RjhRzEX0dl5H5YpEp8OMHwqAdP9EyFDNQI/S5YwqFXfsbfrPtXgmX1WWfB0YaHO +bGoMONI07EBVG2+kODKaxd7fpkMZbruLbkV4pE3ipjRNswYXcTYFw6tx48yaNve/mMD HFaRFjcbhCWuYlCSdf7nt7q/8x8Ej1RMFd6CdwZyD219fZTUXl3tPjCUFWkH/f1vqKhq /L3HsjGEqvPXXL25pY/NA8nmWPmKlvr/kbLLlBKNr3CjRicLzAF/5MXbTZ3dZ2IRikZj qCRw== X-Gm-Message-State: ALQs6tCjgndvyD0fJV+IexaaIBFDSiBXQfCjUlwa6+doFKRCFVYe09zu ZVqEFmz5ZQOLzCryYMH1tozJPGhz8j8= X-Google-Smtp-Source: AIpwx4/3vhcn9RHoAPWQ6RIF9gRuGPXs1VeB1ZF+7sHtbobzfEgQttL0n6eN2LXUZj+cwbnAawfudg== X-Received: by 10.223.135.171 with SMTP id b40mr2727459wrb.156.1523803221084; Sun, 15 Apr 2018 07:40:21 -0700 (PDT) Original-Received: from XPS13 (188.226.99.84.rev.sfr.net. [84.99.226.188]) by smtp.gmail.com with ESMTPSA id k35sm8744478wre.55.2018.04.15.07.40.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 15 Apr 2018 07:40:20 -0700 (PDT) In-reply-to: <834lkf7ely.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: 208.118.235.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:145388 Archived-At: Eli Zaretskii writes: > I'm surprised that the slowdown due to the conversion is so large, > though. It doesn't feel right, even with a 4MB string. I've digged a bit to know why it is so slow, and I've found that if I'm wrapping `json-parse-string` with a `with-temp-buffer`, it is now way faster: results of benchmark-run with a string of 4043212 characters ``` (with-temp-buffer (json-parse-string str)): (0.814315554 1 0.11941178500000005) (json-parse-string str): (11.542233167 1 0.14954429599999997) (with-temp-buffer (json-read-from-string str)): (5.9781185610000005 29 4.967349412000001) (json-read-from-string str): (5.601267 24 4.723292248000001) ``` Any idea why ? The current (buffer-size) is 1063954, if it is relevant. > Yes, it's necessary, because the input string may include raw bytes, > which will crash Emacs if not handled properly. The Jansson documentation guarantee that the strings returned from the library are always UTF-8 encoded [1]. By knowing that guarantee, is it possible to reconsider the use of code_convert_string ? Encoding a string to UTF-8 which is already UTF-8 encoded seems useless.. [1] https://jansson.readthedocs.io/en/2.11/apiref.html#c.json_string_value -- Sebastien Chapuis