unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Pettersson <daniel@dpettersson.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 69241@debbugs.gnu.org, joaotavora@gmail.com
Subject: bug#69241: Fixed patch issues
Date: Mon, 11 Mar 2024 20:39:18 +0100	[thread overview]
Message-ID: <m2a5n4zhg9.fsf@dpettersson.net> (raw)
In-Reply-To: <86wmq8tw55.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 11 Mar 2024 21:18:30 +0200")

[-- Attachment #1: Type: text/plain, Size: 813 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> Write access to the repository is a separate decision.  We usually
> make it after observing your patches and review comments to them over
> some period, to make sure you are on top of our conventions and
> procedures.  So no need to wait for that or see it as a prerequisite
> for your development and maintenance work.

That makes sense, actually I appreciate the hand holding :) Is there any
thing more that you need from me regarding the original issue?  I feel
like I have a decent enough understanding of Jsonrpc so I am happy to be
noted as an maintainer contact in admin/MAINTAINERS.

Also I am a bit bad at reading tones in email form.  I am sorry if I
made any faux pas in this thread.

Re attaching the patch as to not get it confused with the first patch sent.

[-- Attachment #2: PATCH --]
[-- Type: text/x-patch, Size: 3597 bytes --]

From c4d5ddb9ce5cdb8c283928daf6b166e4ce5a430d Mon Sep 17 00:00:00 2001
From: Daniel Pettersson <daniel@dpettersson.net>
Date: Wed, 28 Feb 2024 13:03:56 +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 | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el
index 14fe0447008..5037d8c5b2b 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
@@ -760,10 +760,11 @@ jsonrpc--process-filter
                                 (setq message
                                       (plist-put message :jsonrpc-json
                                                  (buffer-string)))
-                                (process-put proc 'jsonrpc-mqueue
-                                             (nconc (process-get proc
-                                                                 'jsonrpc-mqueue)
-                                                    (list message)))))
+                                ;; Put new messages at the front of the queue,
+                                ;; this is correct as the order is reversed
+                                ;; before putting the timers on `timer-list'.
+                                (push message
+                                      (process-get proc 'jsonrpc-mqueue))))
                           (goto-char message-end)
                           (let ((inhibit-read-only t))
                             (delete-region (point-min) (point)))
@@ -782,11 +783,20 @@ jsonrpc--process-filter
           ;; non-locally (typically the reply to a request), so do
           ;; this all this processing in top-level loops timer.
           (cl-loop
+           ;; `timer-activate' orders timers by time, which is an
+           ;; very expensive operation when jsonrpc-mqueue is large,
+           ;; therefore the time object is reused for each timer
+           ;; created.
+           with time = (current-time)
            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))
+                (timer-activate timer))))))))
 
 (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)


  reply	other threads:[~2024-03-11 19:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-18  1:53 bug#69241: [PATCH] Jsonrpc: improve performance of process filter function Daniel Pettersson
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 [this message]
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=m2a5n4zhg9.fsf@dpettersson.net \
    --to=daniel@dpettersson.net \
    --cc=69241@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=joaotavora@gmail.com \
    /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).