From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Pettersson Newsgroups: gmane.emacs.bugs Subject: bug#69241: Fixed patch issues Date: Wed, 28 Feb 2024 13:22:50 +0100 Message-ID: References: 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="4786"; mail-complaints-to="usenet@ciao.gmane.io" To: 69241@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 28 13:24:23 2024 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 1rfIz1-00012T-5Z for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 28 Feb 2024 13:24:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIyI-0005W9-1h; Wed, 28 Feb 2024 07:23:38 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfIyG-0005VF-Pn for bug-gnu-emacs@gnu.org; Wed, 28 Feb 2024 07:23:36 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfIyG-000508-Ee for bug-gnu-emacs@gnu.org; Wed, 28 Feb 2024 07:23:36 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rfIyg-00010G-Ft for bug-gnu-emacs@gnu.org; Wed, 28 Feb 2024 07:24:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Daniel Pettersson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Feb 2024 12:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69241 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 69241-submit@debbugs.gnu.org id=B69241.17091230083739 (code B ref 69241); Wed, 28 Feb 2024 12:24:02 +0000 Original-Received: (at 69241) by debbugs.gnu.org; 28 Feb 2024 12:23:28 +0000 Original-Received: from localhost ([127.0.0.1]:35596 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rfIy7-0000yC-QN for submit@debbugs.gnu.org; Wed, 28 Feb 2024 07:23:28 -0500 Original-Received: from mail-lf1-f48.google.com ([209.85.167.48]:56616) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rfIy5-0000xg-Kp for 69241@debbugs.gnu.org; Wed, 28 Feb 2024 07:23:26 -0500 Original-Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-512e568607aso5540216e87.1 for <69241@debbugs.gnu.org>; Wed, 28 Feb 2024 04:22:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709122973; x=1709727773; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0n9TbP3WnNHz1wWeX5SaoZQZQIxoTw02hOiSGakuhow=; b=sHWGkSPJVjqGqNF7o/sBbJa5hnqAEd1n0jYiV+iloLSMMtWN67FY5Q4b+V/jPJiKow YdnlCWpuRPssnhEi0+xCHfn1AnjxSr4DLw1tlFb8otQeX6G+ka3NDaj608HvlsWmSGQx GZqEEhAfa4+lETpiA1xkgtqclPFnAsJVy2Y3U49PDvFYiyvJmNVmg93RRPQlm1lF/zIO xyV78w+UXXpZaFV+H5XhRQdfgkEqROeAiH4m0yfVqC/ZGKktPeEasYCRW5Y/e5vrEy3V MjRUbm9G3HBeolB3gwaLtbOfxbp8icNfCU24vHZJBo7ikHRp4r3tRy0p5hs2cGpH6n60 5lEg== X-Gm-Message-State: AOJu0Yyy0bgGGEbCj62YSvtZRWt2GlKHjuFKBf6SQzWyjNazoKxzyFnR 3mcNFM9e9rVYF3RqzyMn/ysIEmX+LHGFL1EEeIGk9DxwNFiipZarrdB4srZr X-Google-Smtp-Source: AGHT+IHVWpS4sQfEj1QGKC68bywCB4errb6wIVLlETQqwgAJ5A5iNmYZ0VVQOB6KVypGdVnRRrPkCw== X-Received: by 2002:a05:6512:114c:b0:512:e506:1c66 with SMTP id m12-20020a056512114c00b00512e5061c66mr10225530lfg.26.1709122972355; Wed, 28 Feb 2024 04:22:52 -0800 (PST) Original-Received: from Daniels-Air (c-72cde455.027-357-6d6c6d4.bbcust.telenor.se. [85.228.205.114]) by smtp.gmail.com with ESMTPSA id h21-20020a19ca55000000b005131149642fsm487787lfj.34.2024.02.28.04.22.51 for <69241@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 04:22:51 -0800 (PST) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280752 Archived-At: --=-=-= Content-Type: text/plain The previous patch included an large regression, where "batch" of messages where handled as an LIFO. This patch should fix the issue and also removes the dependency on timer.el internal apis. Which makes it instead dependent on undocumented behavior that timers of equal time are executed in LIFO order. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-Jsonrpc-improve-performance-of-process-filter-functi.patch Content-Transfer-Encoding: quoted-printable Content-Description: patch >From c4d5ddb9ce5cdb8c283928daf6b166e4ce5a430d Mon Sep 17 00:00:00 2001 From: Daniel Pettersson 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 @@ =20 ;; Author: Jo=C3=A3o T=C3=A1vora ;; Keywords: processes, languages, extensions -;; Version: 1.0.24 +;; Version: 1.0.25 ;; Package-Requires: ((emacs "25.2")) =20 ;; 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 qu= eue, + ;; this is correct as the order is reversed + ;; before putting the timers on `timer-lis= t'. + (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 =3D (current-time) for msg =3D (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 m= sg))) + (list conn msg)) + (timer-activate timer)))))))) =20 (defun jsonrpc--remove (conn id &optional deferred-spec) "Cancel CONN's continuations for ID, including its timer, if it exists. --=20 2.39.3 (Apple Git-145) --=-=-=--