From: Daniel Pettersson <daniel@dpettersson.net>
To: 69241@debbugs.gnu.org
Subject: bug#69241: [PATCH] Jsonrpc: improve performance of process filter function
Date: Sun, 18 Feb 2024 02:53:01 +0100 [thread overview]
Message-ID: <m2cysutu6a.fsf@dpettersson.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 868 bytes --]
Tags: patch
This was issue was discovered during elpa package dape's development,
where an adapter was sending 72000 notifications on startup which leads
to emacs looping over timer--time-less-p for > 50 seconds and after the
fix for less then 1 second. The "integrity" of timer order are messed
with but as timer_check runs all of the ripe timers in the same while
loop it only becomes an question of execution order. This change uses
timer.el internal api `timer--triggered', but this might be fine as it's
tightly coupled with keyboard.
In GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin23.1.0, NS
appkit-2487.20 Version 14.1.1 (Build 23B81)) of 2023-12-20 built on
Daniels-Air
Repository revision: 281be72422f42fcc84d43f50723a3e91b7d03cbc
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2487
System Description: macOS 14.1.1
[-- Attachment #2: 0001-Jsonrpc-improve-performance-of-process-filter-functi.patch --]
[-- Type: text/patch, Size: 2710 bytes --]
From 92eef1a5221dd69dc95a9484eafeacad571246f8 Mon Sep 17 00:00:00 2001
From: Daniel Pettersson <daniel@dpettersson.net>
Date: Sun, 18 Feb 2024 02:05:46 +0100
Subject: [PATCH] Jsonrpc: improve performance of process filter function
`run-at-time' keeps `timer-list' list sorted by inserting each timer
based on the timer value. This means that `timer--time-less-p' needs is
executed ~ N*N/2 times for each N pending messages. This means that
jsonrpc becomes unusable for connections that generate a lot messages at
the same time.
* lisp/jsonrpc.el (Version): Bump to 1.0.25
(jsonrpc--process-filter): Improve performance
---
lisp/jsonrpc.el | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el
index 14fe0447008..9a52b5a76cf 100644
--- a/lisp/jsonrpc.el
+++ b/lisp/jsonrpc.el
@@ -4,7 +4,7 @@
;; Author: João Távora <joaotavora@gmail.com>
;; Keywords: processes, languages, extensions
-;; Version: 1.0.24
+;; Version: 1.0.25
;; Package-Requires: ((emacs "25.2"))
;; This is a GNU ELPA :core package. Avoid functionality that is not
@@ -782,11 +782,22 @@ jsonrpc--process-filter
;; non-locally (typically the reply to a request), so do
;; this all this processing in top-level loops timer.
(cl-loop
+ with time = (timer-relative-time nil 0)
for msg = (pop (process-get proc 'jsonrpc-mqueue)) while msg
- do (run-at-time 0 nil
- (lambda (m) (with-temp-buffer
- (jsonrpc-connection-receive conn m)))
- msg)))))))
+ do (let ((timer (timer-create)))
+ (timer-set-time timer time)
+ (timer-set-function timer
+ (lambda (conn msg)
+ (with-temp-buffer
+ (jsonrpc-connection-receive conn msg)))
+ (list conn msg))
+ (setf (timer--triggered timer) nil)
+ ;; We're bypassing `timer-activate' due to performance
+ ;; concerns. `timer-activate' iterates through all
+ ;; timers scheduled to execute before inserting our
+ ;; callback. While it doesn't maintain the precise
+ ;; order of timers, we should be fine.
+ (setf timer-list (cons timer timer-list)))))))))
(defun jsonrpc--remove (conn id &optional deferred-spec)
"Cancel CONN's continuations for ID, including its timer, if it exists.
--
2.39.3 (Apple Git-145)
next reply other threads:[~2024-02-18 1:53 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-18 1:53 Daniel Pettersson [this message]
2024-02-28 12:22 ` bug#69241: Fixed patch issues Daniel Pettersson
2024-03-09 8:55 ` Eli Zaretskii
2024-03-09 8:56 ` Eli Zaretskii
2024-03-09 10:56 ` João Távora
2024-03-10 14:28 ` Daniel Pettersson
2024-03-10 14:41 ` João Távora
2024-03-11 9:44 ` Daniel Pettersson
2024-03-11 13:11 ` Eli Zaretskii
2024-03-11 14:48 ` Daniel Pettersson
2024-03-11 16:27 ` Eli Zaretskii
2024-03-11 19:03 ` Daniel Pettersson
2024-03-11 19:18 ` Eli Zaretskii
2024-03-11 19:39 ` Daniel Pettersson
2024-03-12 3:27 ` Eli Zaretskii
2024-03-12 13:31 ` Eli Zaretskii
2024-03-12 14:34 ` Daniel Pettersson
2024-03-12 15:00 ` Eli Zaretskii
2024-03-12 13:28 ` Eli Zaretskii
2024-03-12 14:33 ` Daniel Pettersson
2024-03-10 16:46 ` Eli Zaretskii
2024-03-10 20:05 ` Daniel Pettersson
2024-03-10 23:30 ` Daniel Pettersson
2024-03-11 12:24 ` Eli Zaretskii
2024-03-11 12:38 ` Daniel Pettersson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2cysutu6a.fsf@dpettersson.net \
--to=daniel@dpettersson.net \
--cc=69241@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).