GNU bug report logs - #31138
Native json slower than json.el

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Sebastien Chapuis <sebastien@HIDDEN>; Keywords: moreinfo; dated Thu, 12 Apr 2018 19:15:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) moreinfo. Request was from Noam Postavsky <npostavs@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 31138 <at> debbugs.gnu.org:


Received: (at 31138) by debbugs.gnu.org; 15 Apr 2018 15:19:36 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 15 11:19:36 2018
Received: from localhost ([127.0.0.1]:54310 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1f7jRH-00006m-NW
	for submit <at> debbugs.gnu.org; Sun, 15 Apr 2018 11:19:35 -0400
Received: from eggs.gnu.org ([208.118.235.92]:41049)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1f7jRG-00006U-7f
 for 31138 <at> debbugs.gnu.org; Sun, 15 Apr 2018 11:19:34 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <eliz@HIDDEN>) id 1f7jR6-0002BG-RD
 for 31138 <at> debbugs.gnu.org; Sun, 15 Apr 2018 11:19:28 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:46120)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@HIDDEN>)
 id 1f7jR6-0002BA-Ne; Sun, 15 Apr 2018 11:19:24 -0400
Received: from [176.228.60.248] (port=3051 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1f7jR6-00083y-5H; Sun, 15 Apr 2018 11:19:24 -0400
Date: Sun, 15 Apr 2018 18:19:26 +0300
Message-Id: <838t9o4hvl.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Sebastien Chapuis <sebastien@HIDDEN>
In-reply-to: <878t9own1p.fsf@HIDDEN> (message from Sebastien Chapuis on Sun, 
 15 Apr 2018 16:40:18 +0200)
Subject: Re: bug#31138: Native json slower than json.el
References: <87sh806xwa.fsf@HIDDEN> <834lkf7ely.fsf@HIDDEN>
 <878t9own1p.fsf@HIDDEN>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2001:4830:134:3::e
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: 31138
Cc: 31138 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Eli Zaretskii <eliz@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -6.0 (------)

> From: Sebastien Chapuis <sebastien@HIDDEN>
> Cc: 31138 <at> debbugs.gnu.org
> Date: Sun, 15 Apr 2018 16:40:18 +0200
> 
> 
> > 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)
> ```

Interesting.

> Any idea why ?

Where did str come from?  Did you insert it into the buffer or
something?  Could that explain the difference in performance?

More generally, can you post the string you are using for the
benchmarking, and the benchmark code as well?  That would make the
discussion less abstract.

> > 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].

You assume that the library has no bugs, yes?  Because if it does,
then we might crash Emacs by trusting it so much.  Letting invalid
bytes creep into Emacs buffers and strings is a sure recipe for an
eventual crash.

> By knowing that guarantee, is it possible to reconsider the use of
> code_convert_string ?

Since it's already much faster than a Lisp implementation, why would
we want to risk crashing an Emacs session by omitting the decoding?

> Encoding a string to UTF-8 which is already UTF-8 encoded seems
> useless..

It's decoding, not encoding, and the process of decoding examines
every sequence in the byte stream and ensures they are valid UTF-8.

Emacs never trusts any external data to be what the user or Lisp tell
it is; I see no reason why we should make an exception in this
particular case.

Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#31138; Package emacs. Full text available.

Message received at 31138 <at> debbugs.gnu.org:


Received: (at 31138) by debbugs.gnu.org; 15 Apr 2018 14:40:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 15 10:40:29 2018
Received: from localhost ([127.0.0.1]:54283 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1f7ipQ-0007SO-SO
	for submit <at> debbugs.gnu.org; Sun, 15 Apr 2018 10:40:29 -0400
Received: from mail-wr0-f177.google.com ([209.85.128.177]:38066)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <sebastien@HIDDEN>) id 1f7ipP-0007S3-1N
 for 31138 <at> debbugs.gnu.org; Sun, 15 Apr 2018 10:40:27 -0400
Received: by mail-wr0-f177.google.com with SMTP id h3so6571434wrh.5
 for <31138 <at> 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)
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)
References: <87sh806xwa.fsf@HIDDEN> <834lkf7ely.fsf@HIDDEN>
User-agent: mu4e 0.9.19; emacs 27.0.50
From: Sebastien Chapuis <sebastien@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#31138: Native json slower than json.el
In-reply-to: <834lkf7ely.fsf@HIDDEN>
Date: Sun, 15 Apr 2018 16:40:18 +0200
Message-ID: <878t9own1p.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 31138
Cc: 31138 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


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




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#31138; Package emacs. Full text available.

Message received at 31138 <at> debbugs.gnu.org:


Received: (at 31138) by debbugs.gnu.org; 13 Apr 2018 07:24:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 13 03:24:55 2018
Received: from localhost ([127.0.0.1]:49015 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1f6t4p-0002Ii-0B
	for submit <at> debbugs.gnu.org; Fri, 13 Apr 2018 03:24:55 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50978)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1f6t4n-0002IW-OS
 for 31138 <at> debbugs.gnu.org; Fri, 13 Apr 2018 03:24:54 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <eliz@HIDDEN>) id 1f6t4e-0005Dk-LX
 for 31138 <at> debbugs.gnu.org; Fri, 13 Apr 2018 03:24:48 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled
 version=3.3.2
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:56458)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@HIDDEN>)
 id 1f6t4e-0005De-Hd; Fri, 13 Apr 2018 03:24:44 -0400
Received: from [176.228.60.248] (port=1266 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1f6t4d-0006SL-M3; Fri, 13 Apr 2018 03:24:44 -0400
Date: Fri, 13 Apr 2018 10:24:57 +0300
Message-Id: <834lkf7ely.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Sebastien Chapuis <sebastien@HIDDEN>
In-reply-to: <87sh806xwa.fsf@HIDDEN> (message from Sebastien Chapuis on Thu, 
 12 Apr 2018 21:13:41 +0200)
Subject: Re: bug#31138: Native json slower than json.el
References: <87sh806xwa.fsf@HIDDEN>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2001:4830:134:3::e
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: 31138
Cc: 31138 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Eli Zaretskii <eliz@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -6.0 (------)

> From: Sebastien Chapuis <sebastien@HIDDEN>
> Date: Thu, 12 Apr 2018 21:13:41 +0200
> 
> I took a look at the code, and if I remove the call to
> code_convert_string in json_make_string (see the attached diff),
> it's way faster:
> 
> Test with a string of 4042411 characters
> ```
> json-parse-string (without code_convert_string):
> 0.505582 seconds
> ```
> 
> Is this conversion really necessary ?

Yes, it's necessary, because the input string may include raw bytes,
which will crash Emacs if not handled properly.

I'm surprised that the slowdown due to the conversion is so large,
though.  It doesn't feel right, even with a 4MB string.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#31138; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Apr 2018 19:14:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 12 15:14:01 2018
Received: from localhost ([127.0.0.1]:48476 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1f6hfV-0003qd-Id
	for submit <at> debbugs.gnu.org; Thu, 12 Apr 2018 15:14:01 -0400
Received: from eggs.gnu.org ([208.118.235.92]:38182)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <sebastien@HIDDEN>) id 1f6hfT-0003q8-LL
 for submit <at> debbugs.gnu.org; Thu, 12 Apr 2018 15:13:59 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <sebastien@HIDDEN>) id 1f6hfN-0005Vs-FO
 for submit <at> debbugs.gnu.org; Thu, 12 Apr 2018 15:13:54 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:40514)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <sebastien@HIDDEN>) id 1f6hfN-0005Vh-BF
 for submit <at> debbugs.gnu.org; Thu, 12 Apr 2018 15:13:53 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:57314)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <sebastien@HIDDEN>) id 1f6hfI-000794-P1
 for bug-gnu-emacs@HIDDEN; Thu, 12 Apr 2018 15:13:53 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <sebastien@HIDDEN>) id 1f6hfE-0005Sz-Pn
 for bug-gnu-emacs@HIDDEN; Thu, 12 Apr 2018 15:13:48 -0400
Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:34173)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <sebastien@HIDDEN>) id 1f6hfE-0005Sj-HG
 for bug-gnu-emacs@HIDDEN; Thu, 12 Apr 2018 15:13:44 -0400
Received: by mail-wr0-x22e.google.com with SMTP id d19so6130305wre.1
 for <bug-gnu-emacs@HIDDEN>; Thu, 12 Apr 2018 12:13:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=chapu-is.20150623.gappssmtp.com; s=20150623;
 h=user-agent:from:to:subject:date:message-id:mime-version;
 bh=rGrDCdsxroG5C2JgtbFKg5nYokBd1nJzpeg43EFHRF8=;
 b=cSq0jt0RkLFDegTk+O8q9w2FZebiILyNd82Gj2vDG5YO4uL7B8E4mAq/SJs2hjf4hi
 dPMRxpVEy+HMUsAFKfhtoouQoyFUQLMGWaxZo4LHEA4Ta+RTCZzzS70mq6aVMKfp+7EH
 aUpVbie5t0rFBdW8q+2a4vHs1lACH/BErvzuSLk9W/9QqlvbOGz/Rvw+7qqP8LCwAmmx
 2/Lsm3ISCFb7tt2x5olM+0ve/KnpTOk1WLgyw0o/uTX4tmJg3JhlrovT5hTW5HVOgGHm
 80FsdCwIpa4LbPyY7c5DOifD2Gq5Y6fhGkxaroZQZ+UBNJf9jw7yu7xs12P7kneAL5j+
 5rJA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:user-agent:from:to:subject:date:message-id
 :mime-version;
 bh=rGrDCdsxroG5C2JgtbFKg5nYokBd1nJzpeg43EFHRF8=;
 b=qreP/8qaSLCa9H8DSbreBv9TMX/S61S32jkfbrBujYao5vmVmnf/PCI7+LSI9Udl9A
 6NSRH0XSdc4LAyRIAExZtLEiOeKVm3Tf5Wac/7Pj6Qtq+6ZVO29bu0luJ0XJAtb/+Wbe
 8sddeDc8MpCvw/uBD/Nuit4Cxn1asUltgHeSYqMcPzTVF9lg2oocZAKtwz4HNYFelLE3
 AX+1UOsUO+dkv3F+HXo8ux+dv2rHEwX+Q6BH1aRjF3GeErf6cyB82ENsYRXS+gGJY08t
 517s6RcfoTD1y9Fhn74RmKyMRx6lwG0KXcjLBTAmF3rF88u3ZpNoMO2D2KDiYY/M0l5Z
 w//A==
X-Gm-Message-State: ALQs6tAwQSlyHfOhc5QZIsrkM6rZxEv0hX4Y3R32SqwsTuBt8KYWTU3i
 3dRXT0ILj2a4UdYdOvjZ81+OLSlKMr8=
X-Google-Smtp-Source: AIpwx4/JNBn0RL/FtNgPFpNVpFCEhR/AWqj2hQiAWSekaY0NOti0W/NeuhuiStxpx7WpyQDvUYF/Xw==
X-Received: by 10.223.190.142 with SMTP id i14mr1565717wrh.168.1523560422981; 
 Thu, 12 Apr 2018 12:13:42 -0700 (PDT)
Received: from XPS13 (188.226.99.84.rev.sfr.net. [84.99.226.188])
 by smtp.gmail.com with ESMTPSA id a70sm96552wma.27.2018.04.12.12.13.41
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Thu, 12 Apr 2018 12:13:42 -0700 (PDT)
User-agent: mu4e 0.9.19; emacs 27.0.50
From: Sebastien Chapuis <sebastien@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: Native json slower than json.el
Date: Thu, 12 Apr 2018 21:13:41 +0200
Message-ID: <87sh806xwa.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

--=-=-=
Content-Type: text/plain


Hi,

I have tested the new function json-parse-string to use it in lsp-mode
and was suprised when I found out that this function is slower than
json-read-from-string from json.el:

Test with a string of 4042446 characters:
```
json-parse-string:       9,166010 seconds
json-read-from-string:   6.028625 seconds
```

I took a look at the code, and if I remove the call to
code_convert_string in json_make_string (see the attached diff),
it's way faster:

Test with a string of 4042411 characters
```
json-parse-string (without code_convert_string):
0.505582 seconds
```

Is this conversion really necessary ? Should I set some variable to avoid
this ?


By the way, what is the state of this patch:
https://lists.gnu.org/archive/html/emacs-devel/2017-12/msg00916.html
Could it be merge ?


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=json.patch
Content-Description: patch

diff --git a/src/json.c b/src/json.c
index b046d34f66..1fc976214d 100644
--- a/src/json.c
+++ b/src/json.c
@@ -219,8 +219,7 @@ json_has_suffix (const char *string, const char *suffix)
 static Lisp_Object
 json_make_string (const char *data, ptrdiff_t size)
 {
-  return code_convert_string (make_specified_string (data, -1, size, false),
-                              Qutf_8_unix, Qt, false, true, true);
+  return make_specified_string (data, -1, size, false);
 }
 
 /* Create a multibyte Lisp string from the null-terminated UTF-8

--=-=-=
Content-Type: text/plain


--
Sebastien Chapuis

--=-=-=--




Acknowledgement sent to Sebastien Chapuis <sebastien@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#31138; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Wed, 18 Apr 2018 02:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.