From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#46761: 28.0.50; Speed up json.el encoding Date: Thu, 25 Feb 2021 18:21:20 +0000 Message-ID: <87ft1kgg9r.fsf@tcd.ie> References: <87a6rtszgk.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13525"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: 46761@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 25 19:22:24 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lFLHM-0003Qu-1L for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 25 Feb 2021 19:22:24 +0100 Original-Received: from localhost ([::1]:51450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFLHL-0000Eb-3X for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 25 Feb 2021 13:22:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFLH4-0000EP-CS for bug-gnu-emacs@gnu.org; Thu, 25 Feb 2021 13:22:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lFLH0-00016Q-Gd for bug-gnu-emacs@gnu.org; Thu, 25 Feb 2021 13:22:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lFLH0-00072m-D8 for bug-gnu-emacs@gnu.org; Thu, 25 Feb 2021 13:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 Feb 2021 18:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46761 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 46761-submit@debbugs.gnu.org id=B46761.161427729227037 (code B ref 46761); Thu, 25 Feb 2021 18:22:02 +0000 Original-Received: (at 46761) by debbugs.gnu.org; 25 Feb 2021 18:21:32 +0000 Original-Received: from localhost ([127.0.0.1]:39223 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lFLGV-000721-S4 for submit@debbugs.gnu.org; Thu, 25 Feb 2021 13:21:32 -0500 Original-Received: from mail-wm1-f43.google.com ([209.85.128.43]:51300) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lFLGS-00071m-UV for 46761@debbugs.gnu.org; Thu, 25 Feb 2021 13:21:31 -0500 Original-Received: by mail-wm1-f43.google.com with SMTP id g11so1692415wmh.1 for <46761@debbugs.gnu.org>; Thu, 25 Feb 2021 10:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=oNhyEoebcn38DeRCE4wc0+PgMlLLZ1kCGhGm311fHgE=; b=DsdZmLZ7KrNSN51DwngYcATLcYyFyl/TfE36/VLpd/wt4EXvBgM2zXegad3stVpV2S 2qkFbfHV3F8jLe82OyqFdhQYf7lNBAA5NXSPjYEINXp728k7mAqK7oUDO8/9cgSf7xXo GllcjUEtyBwc1QmRnDFrwG/t/NW1gRP4qG2nidR0yPefv3m5DbPtmoHdjmZPqfgb3dY8 WgC5nLdlIpshRFI17oKlNhiXQeyrvLXb5fJsXAEpT+UZvhZ6iwObeLYBfl5fNaMskiri T8rjI773fhcANrdHRR3AbQjuzLFvyiDBXX6zWN5GRd+66FOuoe67luQpW42/1DUCpZ3j IuOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=oNhyEoebcn38DeRCE4wc0+PgMlLLZ1kCGhGm311fHgE=; b=dfVLefpOfoP1IYcKFdFp5Twg8KRGBLn3PXzuWrXrZC76vZ8xsvPVtnFvmx071kdDqA 9by8dYNR/cy8Dv7UXtUwjHP/GjPtlH2Q2e/mUm65pVZ44wsfnyL4vw+QSwqUaePN69ja n4/pAczKuMMA/U6AnvoU5S+Wj/VSXnby/QiY9nGLCEbL+Er8/9YwOjHSKXXfna+zz2fF UVsiDPiWzR3DOq2KFgyXGVwkPlt0ftAvTweO0YtBwWBELqKlQv5s155vpGDi4AtqQwfB cbxjuxopRRSQDqu5yWBiwqSfp/VC5kQZ59LDDmBt5sSgjtE/1H+04qaiKYVdK6jbHSpU 4GMw== X-Gm-Message-State: AOAM533ZNotWVzGH8XMPcaCTMKaZKyszUTUNdnAIjnlAC/q7ENmk5XJ2 X55lMGuJgUT4JQYlEj3kdtrHZUJ0vjsOkg== X-Google-Smtp-Source: ABdhPJzLh8sS9hxVi9Y1qNGlQDWKRGt9Focmb1YnZY+AUOrxCSLISsAgS4r+lBZcI9MIupovnHGpkw== X-Received: by 2002:a1c:a916:: with SMTP id s22mr4491949wme.82.1614277282675; Thu, 25 Feb 2021 10:21:22 -0800 (PST) Original-Received: from localhost ([2a02:8084:20e2:c380:d15:339e:aa10:60f1]) by smtp.gmail.com with ESMTPSA id y16sm9469512wrw.46.2021.02.25.10.21.21 for <46761@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 10:21:21 -0800 (PST) In-Reply-To: <87a6rtszgk.fsf@tcd.ie> (Basil L. Contovounesios's message of "Thu, 25 Feb 2021 01:33:47 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:200806 Archived-At: --=-=-= Content-Type: text/plain "Basil L. Contovounesios" writes: > The attached patch speeds up json-encode by inserting into a buffer > rather than concatenating strings. It does so backward compatibly by > creating a new json--print-* namespace that mirrors the existing > json-encode-* namespace, cleaning it up a bit and reducing code > duplication in the process. > > Using my usual benchmark from bug#40693#89: > > canada.json > old (1.412693239 96 0.736882091) > new (1.154423962 32 0.248241551) > > citm_catalog.json > old (0.676292855 68 0.5285956769999993) > new (0.306573098 12 0.0965493740000003) > > twitter.json > old (0.353447016 40 0.28536439900000055) > new (0.142140227 8 0.05943713899999992) This additional change: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=json.diff diff --git a/lisp/json.el b/lisp/json.el index eb655162d3..461f688f9c 100644 --- a/lisp/json.el +++ b/lisp/json.el @@ -199,6 +199,8 @@ json--with-output-to-string (with-current-buffer standard-output ;; This affords decent performance gains. (setq-local inhibit-modification-hooks t) + ;; Ignore `read-only' property once and for all (bug#43549). + (setq-local inhibit-read-only t) ,@body))) (defmacro json--with-indentation (&rest body) @@ -458,9 +460,9 @@ json-read-string (defun json--print-string (string &optional from) "Insert a JSON representation of STRING at point. FROM is the index of STRING to start from and defaults to 0." - (goto-char (prog1 (1+ (point)) - ;; Strip `read-only' property (bug#43549). - (insert ?\" (substring-no-properties string from)))) + (goto-char (prog1 (1+ (point)) (insert ?\" string))) + (set-text-properties (point) (point-max) ()) + (and from (delete-char from)) ;; Escape only quotation mark, backslash, and the control ;; characters U+0000 to U+001F (RFC 4627, ECMA-404). (while (re-search-forward (rx (in ?\" ?\\ cntrl)) nil 'move) --=-=-= Content-Type: text/plain improves things slightly further (slight inconsistencies with the above are because my laptop's currently on battery power): canada.json old (1.450930341 96 0.7616264250000002) new (1.161926076 32 0.24752529000000045) citm_catalog.json old (0.686048204 68 0.5394565070000006) new (0.267222201 6 0.048179708000000154) twitter.json old (0.362725099 40 0.2935560630000005) new (0.099399607 2 0.01469844000000009) And yes, I have added a test case for this locally. -- Basil --=-=-=--