From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#31138: Native json slower than json.el Date: Mon, 22 Apr 2019 19:16:15 +0300 Message-ID: References: <87sh806xwa.fsf@chapu.is> <83zhphliil.fsf@gnu.org> <181b93a3-3861-0481-1b95-8344410d1049@yandex.ru> <83r2a2hdxn.fsf@gnu.org> <21f68973-a684-2a65-82eb-c8f3df90127f@yandex.ru> <83d0lmgez2.fsf@gnu.org> <7d503be9-4d85-3d0b-6829-631ad376ba3d@yandex.ru> <831s22gcci.fsf@gnu.org> <83y349gasn.fsf@gnu.org> <83d0lfag4x.fsf@gnu.org> <5cf45a21-65c3-67ee-f123-be83a6ee7c99@yandex.ru> <83a7gjaen6.fsf@gnu.org> <10ca4e2f-b116-16bc-c81e-24036752c867@yandex.ru> <83lg026xxb.fsf@gnu.org> <0d42dab4-6c5c-be3a-d402-f17b39e7fc3c@yandex.ru> <83k1fm6vly.fsf@gnu.org> <19b19dec-a5a0-e08d-6026-0b9621d38143@yandex.ru> <8336ma6oia.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------0D8953A14BB051FFBFDF3DA1" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="77114"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 Cc: p.stephani2@gmail.com, sebastien@chapu.is, yyoncho@gmail.com, 31138@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 22 18:17:15 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 1hIbd4-000JvT-8A for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Apr 2019 18:17:14 +0200 Original-Received: from localhost ([127.0.0.1]:39715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIbd2-00013B-TF for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Apr 2019 12:17:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIbct-000135-IR for bug-gnu-emacs@gnu.org; Mon, 22 Apr 2019 12:17:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hIbcs-0006iT-IL for bug-gnu-emacs@gnu.org; Mon, 22 Apr 2019 12:17:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37814) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hIbcs-0006iH-F9 for bug-gnu-emacs@gnu.org; Mon, 22 Apr 2019 12:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hIbcs-0003K6-94 for bug-gnu-emacs@gnu.org; Mon, 22 Apr 2019 12:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Apr 2019 16:17: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.155594978712718 (code B ref 31138); Mon, 22 Apr 2019 16:17:02 +0000 Original-Received: (at 31138) by debbugs.gnu.org; 22 Apr 2019 16:16:27 +0000 Original-Received: from localhost ([127.0.0.1]:51356 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIbcH-0003J3-Pl for submit@debbugs.gnu.org; Mon, 22 Apr 2019 12:16:27 -0400 Original-Received: from mail-wr1-f65.google.com ([209.85.221.65]:44476) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIbcG-0003Iq-4e for 31138@debbugs.gnu.org; Mon, 22 Apr 2019 12:16:24 -0400 Original-Received: by mail-wr1-f65.google.com with SMTP id c5so7508603wrs.11 for <31138@debbugs.gnu.org>; Mon, 22 Apr 2019 09:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=BUW/83HveZQE7Omxwxc33TcAPlYmffR0jqN2JUsKC78=; b=mQKz8QEBNjvIj/c53+kva4e/5BzzqzgEpcoVzXOEsEbBlpl3cyk+BM09kcm6PTnpcr 4KdihqfQxTppI84PnkQ8cPawGtt7wZg1hBmBCkvAMTchWF3JHS7AFdX+knxuwhFTG/GO Hq9XowFo5aOXcxVLLa/U+66zGNoCsZK1ucgJzvAf74JmmxX8cYyFqhNA11blBM/RHNA7 R9++UmhX75FCkn3LQCUMCniBZYXTo2ODjSl65MY8Xkc9LQk7Cm5axXQY5swmeJwvsU5z 14UpWv8oT2eHHckF96Ma9eHAISAwyWKmbJfc2s4jRFXaiImNegws0WdHReVcmUUMnHQk YsGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=BUW/83HveZQE7Omxwxc33TcAPlYmffR0jqN2JUsKC78=; b=PXCf+TjDWeYuslmXt0bDBSg8e1by/pdiFKKSFj5NbUqxkvZIRcvxPRAYa7vDaQsxPC /waJOz2doTRWu+1Ihqr6aTZEkvVw5Pa22cVZ3oXdDF2a7740staQuKfbgkp6yKFc4jZM Hbti0AoVmY8mTBRpMHh2mLYE78bKYnJvT/n2bhcQXeNBAzWiMl2NqMtMtzdTmFtZuA8Y TFW3OyAxqRAZCIyQjZwVidDeftv2LVIT3DNqEY5u/wd7k7wY5bMcB3OVzR4S7QWMK4Tr 9DSm4RSWJ1zSxWHaIrAtfku/TaiuViZouXZVMOpgaJmd1OO+IwtemycWxVp05XblXb0Y Q4tQ== X-Gm-Message-State: APjAAAUF5Mj3xBRG/8ZmrdT8yhlIqeZLHLQB6qyTbfJmvi9aR44re/c6 0TNz5iDj6Dnf9nFDvZLQMGo1YPCY X-Google-Smtp-Source: APXvYqzQ98PBFVQW840BCSHQKq6Fm7lRosFKdW2vciLDyPHQbEs0jfcwDQdv/Ifg7JbyCOpWIezW8g== X-Received: by 2002:adf:eed1:: with SMTP id a17mr13304393wrp.268.1555949778227; Mon, 22 Apr 2019 09:16:18 -0700 (PDT) Original-Received: from [192.168.0.195] ([109.110.245.170]) by smtp.googlemail.com with ESMTPSA id o27sm1967742wro.40.2019.04.22.09.16.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Apr 2019 09:16:17 -0700 (PDT) In-Reply-To: <8336ma6oia.fsf@gnu.org> Content-Language: en-US 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:158055 Archived-At: This is a multi-part message in MIME format. --------------0D8953A14BB051FFBFDF3DA1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 22.04.2019 18:36, Eli Zaretskii wrote: > Let's start with just ASCII strings, and then consider moving to valid > UTF-8 sequences. I take it you can easily write a loop that ensures a > string is pure ASCII? All right. Does the attached json_encode_string_ascii_test.diff look good to you? In terms of correctness/safety, I mean. > No, I meant a test of performance. if we begin by testing for plain > ASCII strings, then non-ASCII strings will take longer to convert. > The existing tests are too short to support measurement of the effect, > we need a larger JSON object with many non-ASCII strings. Makes sense. > Suit yourself, but I don't like investing hours in code just to hear > "your best is not good enough" from those who triggered the changes to > begin with. I have code that parses JSON as well. Mentioned that before. > I don't want to make changes that affect decoding everywhere, because > having raw bytes in other cases is a more frequent phenomenon. Let's > just optimize JSON parsing, OK? > > Should be 'true', right? Erm, right. >_< Probably hit 'undo' one too many times. I've attached this patch as json_make_string_no_validation.diff. --------------0D8953A14BB051FFBFDF3DA1 Content-Type: text/x-patch; name="json_make_string_ascii_test.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="json_make_string_ascii_test.diff" diff --git a/src/json.c b/src/json.c index 928825e034..033fa27638 100644 --- a/src/json.c +++ b/src/json.c @@ -225,8 +225,17 @@ 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); + ptrdiff_t nchars, multibyte_nbytes; + parse_str_as_multibyte ((const unsigned char *) data, size, + &nchars, &multibyte_nbytes); + + if (size == nchars) + /* Wasn't sure if the last arg should better be true here, but + it doesn't seem to affect the behavior or correctness, so far. */ + return make_specified_string (data, -1, size, false); + else + return code_convert_string (make_specified_string (data, -1, size, false), + Qutf_8_unix, Qt, false, true, true); } /* Create a multibyte Lisp string from the NUL-terminated UTF-8 --------------0D8953A14BB051FFBFDF3DA1 Content-Type: text/x-patch; name="json_make_string_no_validation.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="json_make_string_no_validation.diff" diff --git a/src/json.c b/src/json.c index 928825e034..b06d411032 100644 --- a/src/json.c +++ b/src/json.c @@ -225,8 +225,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, true); } /* Create a multibyte Lisp string from the NUL-terminated UTF-8 --------------0D8953A14BB051FFBFDF3DA1--