bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31138: Native json slower than json.el


From: Eli Zaretskii
Subject: bug#31138: Native json slower than json.el
Date: Sat, 23 Mar 2019 10:15:26 +0200

> From: Sébastien Chapuis <sebastien@chapu.is>
> Date: Sat, 23 Mar 2019 09:59:23 +0800
> Cc: 31138@debbugs.gnu.org, yyoncho@gmail.com
> 
> I tried to find the cause of this but still without any success.
> Here is a reproducible case:
> 
> You can download the json file at:
> https://gist.githubusercontent.com/yyoncho/dec968b69185305ed02741e18b27a82d/raw/334b0a51bc52cc3c98edb8ff4bccb5fc4531842b/large.json
> 
> Open the file with `emacs -Q large.json`.
> Switch to the scratch buffer and run:
> 
> ```
> (with-current-buffer  "large.json"
>   (benchmark-run 10 (json-parse-string (buffer-string))))
> ;;; (2.5371836119999998 10 0.111044641)
> 
> (with-current-buffer  "large.json"
>   (let ((str (buffer-string)))
>     (benchmark-run 10 (with-temp-buffer (json-parse-string str)))))
> ;;; (1.510604359 10 0.13192760000000003)
> 
> (with-current-buffer  "large.json"
>   (let ((str (buffer-string)))
>     (benchmark-run 10 (with-temp-buffer (json-read-from-string str)))))
> ;;; (1.970248228 114 1.058150570000001)
> ```

Is this with the latest Emacs master branch?  If not, can you try the
latest master?

FWIW, I cannot reproduce your results with the current master.  I get
the following times:

  (with-current-buffer  "large.json"
    (let ((str (buffer-string)))
      (benchmark-run 10 (with-temp-buffer (json-parse-string str)))))
  (0.78125 10 0.15625)

  (with-current-buffer  "large.json"
    (benchmark-run 10
      (progn (goto-char (point-min))
             (json-parse-buffer))))
  (0.890625 10 0.140625)

  (with-current-buffer  "large.json"
    (let ((str (buffer-string)))
      (benchmark-run 10 (with-temp-buffer (json-read-from-string str)))))
  (2.84375 126 1.21875)

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

Please note that in my experiments I visited the large.json file with
find-file-literally, not with find-file.  In my testing, I didn't see
any difference in timings either way, but visiting literally is more
correct for the real-life use cases.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]