[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement 8aea26acef 1/2: Add/Change: (ement--json-parse-bu
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement 8aea26acef 1/2: Add/Change: (ement--json-parse-buffer) Use Jansson functions |
Date: |
Fri, 8 Sep 2023 21:57:49 -0400 (EDT) |
branch: externals/ement
commit 8aea26acefd9e3eafa24db240e41aa9d41603586
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add/Change: (ement--json-parse-buffer) Use Jansson functions
The json.el docstrings and the JSON section of the Elisp info manual
don't make this clear, but in order to use the libjansson functions
for parsing JSON, one must call them; json-read, et al remain
Elisp-based.
Some simple testing shows that this results in a 3-5x speed increase
for parsing JSON responses; for a 38 MB response, the numbers show
23.6 seconds using json-read, and 4.1 seconds using the Jansson-based
json-parse-buffer.
Thanks to Ryan Rix (@rrix) for discovering this!
---
README.org | 1 +
ement-lib.el | 11 +++++++++++
ement.el | 4 ++--
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/README.org b/README.org
index e6dacff9b7..0512457643 100644
--- a/README.org
+++ b/README.org
@@ -305,6 +305,7 @@ Ement.el doesn't support encrypted rooms natively, but it
can be used transparen
+ Room buffer bindings:
+ ~ement-room-goto-next~ and ~ement-room-goto-prev~ are bound to ~n~ and
~p~, respectively.
+ ~ement-room-goto-fully-read-marker~ is bound to ~M-g M-p~ (the mnemonic
being "go to previously read").
++ Use Emacs's Jansson-based JSON-parsing functions when available. (This
results in a 3-5x speed improvement for parsing JSON responses, which can be
significant for large initial sync responses. Thanks to
[[https://github.com/rrix/][Ryan Rix]] for discovering this!)
*Fixes*
diff --git a/ement-lib.el b/ement-lib.el
index 8df14866fc..7b82ecc65f 100644
--- a/ement-lib.el
+++ b/ement-lib.el
@@ -92,6 +92,17 @@ that stray such forms don't remain if the function is
removed."
;; These workarounds should be removed when they aren't needed.
+(defalias 'ement--json-parse-buffer
+ ;; For non-libjansson builds (those that do have libjansson will see a 4-5x
improvement
+ ;; in the time needed to parse JSON responses).
+
+ ;; TODO: Suggest mentioning in manual and docstrings that `json-read', et al
do not use
+ ;; libjansson, while `json-parse-buffer', et al do.
+ (if (fboundp 'json-parse-buffer)
+ (lambda () (json-parse-buffer :object-type 'alist :null-object nil
+ :false-object :json-false))
+ 'json-read))
+
;;;;; Emacs 28 color features.
;; Copied from Emacs 28. See
<https://github.com/alphapapa/ement.el/issues/99>.
diff --git a/ement.el b/ement.el
index 05a639301e..8eb9187ca2 100644
--- a/ement.el
+++ b/ement.el
@@ -552,13 +552,13 @@ a filter ID). When unspecified, the value of
plz-error)))
(_ (signal 'ement-api-error (list
"Ement: Unrecognized network error" plz-error)))))))
:json-read-fn (lambda ()
- "Print a message, then call
`json-read'."
+ "Print a message, then call
`ement--json-parse-buffer'."
(when (ement--sync-messages-p
session)
(message "Ement: Response arrived
after %.2f seconds. Reading %s JSON response..."
(- (time-to-seconds)
sync-start-time)
(file-size-human-readable
(buffer-size))))
(let ((start-time (time-to-seconds)))
- (prog1 (json-read)
+ (prog1 (ement--json-parse-buffer)
(when (ement--sync-messages-p
session)
(message "Ement: Reading JSON
took %.2f seconds"
(- (time-to-seconds)
start-time)))))))))