From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#69241: Fixed patch issues Date: Mon, 11 Mar 2024 14:24:00 +0200 Message-ID: <86jzm9ufbz.fsf@gnu.org> References: <86msr7ye9h.fsf@gnu.org> <86y1aquj9m.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31856"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 69241@debbugs.gnu.org, joaotavora@gmail.com To: Daniel Pettersson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 11 13:25:00 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 1rjeiB-00081V-Nh for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Mar 2024 13:24:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjehi-0006vD-GH; Mon, 11 Mar 2024 08:24:30 -0400 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 1rjehg-0006ur-Uy for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 08:24:29 -0400 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 1rjehg-0000fY-Kd for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 08:24:28 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rjeiE-0007gL-5q for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 08:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Mar 2024 12:25: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.171015988829499 (code B ref 69241); Mon, 11 Mar 2024 12:25:02 +0000 Original-Received: (at 69241) by debbugs.gnu.org; 11 Mar 2024 12:24:48 +0000 Original-Received: from localhost ([127.0.0.1]:39176 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjehz-0007fh-QA for submit@debbugs.gnu.org; Mon, 11 Mar 2024 08:24:48 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38252) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjehu-0007fQ-OL for 69241@debbugs.gnu.org; Mon, 11 Mar 2024 08:24:46 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjehH-0000Z3-7S; Mon, 11 Mar 2024 08:24:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=D97RUUh3100p21revjuuYS6HbgTpxd1bgMaakIiTKEo=; b=IZdkvQUUPOJF TV4kWgYosi0PbUn4qPw8cyVRMEjqf/G3K4vEoQuwuMYE5hSKDHHPMzpq0LdHthrrUI7vj4jR9zjiy QWmrykn9x2PZ+PuYIwQWXAJrXajlQMywyNzeS5O7bUlvQtSzrtZyGCiOmdR4iET5XJfAbzyDsqTsd S300//QUcMkXTgBx91N8Zvps5cyfo1ZzAE3501KLFLmrzd4GLtre29NEiznRsKjmrtHiIyf/i8Aif btiWA4TxakZowtf2LEzz0kIMcJDwynkZ2KDr05LI68633Facto6rd6ZErbwUerOJORj0J5yVD+lY1 B69Xt2YzWFc8OOszu4s8cQ==; In-Reply-To: (message from Daniel Pettersson on Sun, 10 Mar 2024 21:05:46 +0100) 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:281465 Archived-At: > From: Daniel Pettersson > Cc: joaotavora@gmail.com, 69241@debbugs.gnu.org > Date: Sun, 10 Mar 2024 21:05:46 +0100 > > Eli Zaretskii writes: > > > Thank you. Should we reflect that in admin/MAINTAINERS? > > That is fine by me. I am not sure what the impact of that would be? Just that you express interest in this package and don't mind to be CC'ed when some issue about it comes up. > > I don't see where the list is sorted with the above behavior. Can you > > point out which code you allude to? > > Let's continue use the implementation on `master' and my example to > give it some. > > In my example process property 'jsonrpc-mqueue is an list of ~50,000 > messages. > > In `jsonrpc--process-filter' we evaluate `run-at-time' macro, which in > turn invokes `timer--activate'. > > (cl-defun jsonrpc--process-filter (proc string) > ... > (cl-loop > 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))))))) > > `timer--active' makes sure that the `timer-list' is sorted by time to > trigger in ascending order: > > (defun timer--activate (timer &optional triggered-p reuse-cell idle) > ... > ;; Skip all timers to trigger before the new one. > (while (and timers (timer--time-less-p (car timers) timer)) > (setq last timers > timers (cdr timers))) > ;; Insert new timer after last which possibly means in front of queue. > (setf (cond (last (cdr last)) > (idle timer-idle-list) > (t timer-list)) > reuse-cell) > > This is especially bad when the time of the timer is created inside a > loop as in `jsonrpc--process-filter'. > > Let's take the last loop iteration in the `cl-loop'; timer_{N} from > N messages. > > timer_{N} will always be compared with timer_{1}, timer_{2}, > ... timer_{N-2}, timer_{N-1}. > > This ends up with doing N^2/2 timer comparisons in > `jsonrpc--process-filter'. So the problem is not with timer--activate, the problem is with jsonrpc--process-filter which calls timer--activate, and the net effect of those two is the N^2 complexity, is that right? Your original statement was that the list of timers is sorted with N^2 complexity, and that is the part to which I responded.