From: "Mattias Engdegård" <mattiase@acm.org>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: 35418@debbugs.gnu.org
Subject: bug#35418: [PATCH] Don't poll auto-revert files that use notification
Date: Mon, 29 Apr 2019 20:29:07 +0200 [thread overview]
Message-ID: <BB3D2DC1-0C12-44F6-87D3-03CA878ED69E@acm.org> (raw)
In-Reply-To: <87imuxxawj.fsf@gmx.de>
[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]
29 apr. 2019 kl. 14.18 skrev Michael Albinus <michael.albinus@gmx.de>:
>
>> I decided to maintain it as a derived state
>> because it felt silly to replace O(1) code with O(N), and the
>> invariant is clear enough (stated in its doc string). (Some of the
>> places where the variable is updated are O(N) but less frequently
>> executed.)
>
> Yes, but is N large enough to experience the difference?
These things are tricky to measure, but obviously inefficient code just doesn't feel right to write. For example, generating a list just to see if it is non-empty, when that could be determined in a more straightforward way.
> My proposal was to use it NOT as a predicate, but as a function
> returning the buffer list.
Very well; here is an incremental patch (to make the differences clear). It's a compromise: the derived state is gone, but there are two functions: one for the list of buffers that need to be polled, and one for whether that list would be non-empty.
By the way, the patch now uses functions from cl-lib, not just macros. Is there any reason not to?
[-- Attachment #2: 0001-Eliminate-the-auto-revert-polled-buffers-variable.patch --]
[-- Type: application/octet-stream, Size: 5518 bytes --]
From e3fe91d6b760b8325c352e6220997f569f7f2d44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Mon, 29 Apr 2019 20:21:32 +0200
Subject: [PATCH] Eliminate the auto-revert--polled-buffers variable
Instead of maintaining the `auto-revert--polled-buffers' variable,
calculate it when needed. When only its emptiness is of interest,
do so in a more efficient way.
---
lisp/autorevert.el | 46 ++++++++++++++++++++++------------------------
1 file changed, 22 insertions(+), 24 deletions(-)
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index b16b1b5833..6387ef1e92 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -107,7 +107,7 @@
;; Dependencies:
-(eval-when-compile (require 'cl-lib))
+(require 'cl-lib)
(require 'timer)
(require 'filenotify)
@@ -342,11 +342,6 @@ the list of old buffers.")
(defvar auto-revert-tail-pos 0
"Position of last known end of file.")
-(defvar auto-revert--polled-buffers ()
- "List of buffers in Auto-Revert Mode that must be polled.
-It contains the buffers in `auto-revert-buffer-list' whose
-`auto-revert-notify-watch-descriptor' is nil.")
-
(defun auto-revert-find-file-function ()
(setq-local auto-revert-tail-pos
(file-attribute-size (file-attributes buffer-file-name))))
@@ -374,12 +369,8 @@ This has been reported by a file notification event.")
(defun auto-revert-remove-current-buffer (&optional buffer)
"Remove BUFFER from `auto-revert-buffer-list'.
BUFFER defaults to `current-buffer'."
- (unless buffer
- (setq buffer (current-buffer)))
(setq auto-revert-buffer-list
- (delq buffer auto-revert-buffer-list))
- (setq auto-revert--polled-buffers
- (delq buffer auto-revert--polled-buffers)))
+ (delq (or buffer (current-buffer)) auto-revert-buffer-list)))
;;;###autoload
(define-minor-mode auto-revert-mode
@@ -399,7 +390,6 @@ without being changed in the part that is already in the buffer."
(if auto-revert-mode
(when (not (memq (current-buffer) auto-revert-buffer-list))
(push (current-buffer) auto-revert-buffer-list)
- (push (current-buffer) auto-revert--polled-buffers)
(add-hook
'kill-buffer-hook
#'auto-revert-remove-current-buffer
@@ -516,12 +506,26 @@ specifies in the mode line."
(not (memq buf auto-revert-buffer-list)))
(auto-revert-notify-rm-watch))))))
+(defun auto-revert--polled-buffers ()
+ "List of buffers that need to be polled."
+ (cond (global-auto-revert-mode (buffer-list))
+ (auto-revert-always-poll auto-revert-buffer-list)
+ (t (mapcan (lambda (buffer)
+ (and (not (buffer-local-value
+ 'auto-revert-notify-watch-descriptor buffer))
+ (list buffer)))
+ auto-revert-buffer-list))))
+
+;; Same as above in a boolean context, but cheaper.
(defun auto-revert--need-polling-p ()
"Whether periodic polling is required."
(or global-auto-revert-mode
(if auto-revert-always-poll
auto-revert-buffer-list
- auto-revert--polled-buffers)))
+ (not (cl-every (lambda (buffer)
+ (buffer-local-value
+ 'auto-revert-notify-watch-descriptor buffer))
+ auto-revert-buffer-list)))))
(defun auto-revert-set-timer ()
"Restart or cancel the timer used by Auto-Revert Mode.
@@ -592,8 +596,6 @@ will use an up-to-date value of `auto-revert-interval'"
(gethash auto-revert-notify-watch-descriptor
auto-revert--buffers-by-watch-descriptor))
auto-revert--buffers-by-watch-descriptor)
- (setq auto-revert--polled-buffers
- (delq (current-buffer) auto-revert--polled-buffers))
(add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch nil t)))))
;; If we have file notifications, we want to update the auto-revert buffers
@@ -644,12 +646,10 @@ system.")
;; A buffer w/o a file, like dired.
(null buffer-file-name))
(auto-revert-notify-rm-watch)
- (when (memq buffer auto-revert-buffer-list)
- (unless (memq buffer auto-revert--polled-buffers)
- (push buffer auto-revert--polled-buffers))
- ;; Restart the timer if it wasn't running.
- (unless auto-revert-timer
- (auto-revert-set-timer))))))
+ ;; Restart the timer if it wasn't running.
+ (when (and (memq buffer auto-revert-buffer-list)
+ (not auto-revert-timer))
+ (auto-revert-set-timer)))))
;; Loop over all buffers, in order to find the intended one.
(cl-dolist (buffer buffers)
@@ -811,9 +811,7 @@ Auto-Revert Mode from `auto-revert-buffer-list', and for canceling
the timer when no buffers need to be checked."
(save-match-data
- (let ((bufs (cond (global-auto-revert-mode (buffer-list))
- (auto-revert-always-poll auto-revert-buffer-list)
- (t auto-revert--polled-buffers)))
+ (let ((bufs (auto-revert--polled-buffers))
remaining new)
;; Buffers with remote contents shall be reverted only if the
;; connection is established already.
--
2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-04-29 18:29 UTC|newest]
Thread overview: 101+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-24 18:14 bug#35418: [PATCH] Don't poll auto-revert files that use notification Mattias Engdegård
2019-04-24 18:58 ` Eli Zaretskii
2019-04-24 19:36 ` Michael Albinus
2019-04-26 20:46 ` Mattias Engdegård
2019-04-27 9:40 ` Michael Albinus
2019-04-27 16:28 ` Mattias Engdegård
2019-04-25 9:56 ` Mattias Engdegård
2019-04-25 10:04 ` Eli Zaretskii
2019-04-25 18:07 ` Mattias Engdegård
2019-04-27 9:27 ` Michael Albinus
2019-04-27 9:54 ` Eli Zaretskii
2019-04-27 10:23 ` Michael Albinus
2019-04-27 16:19 ` Mattias Engdegård
2019-04-27 16:52 ` Eli Zaretskii
2019-04-28 10:21 ` Mattias Engdegård
2019-04-29 7:53 ` Michael Albinus
2019-04-29 11:06 ` Mattias Engdegård
2019-04-29 12:18 ` Michael Albinus
2019-04-29 16:24 ` Eli Zaretskii
2019-04-29 18:29 ` Mattias Engdegård [this message]
2019-04-29 20:17 ` Michael Albinus
2019-04-30 3:57 ` Eli Zaretskii
2019-04-30 11:41 ` Mattias Engdegård
2019-04-30 12:59 ` Michael Albinus
2019-04-30 13:56 ` Mattias Engdegård
2019-04-30 14:19 ` Michael Albinus
2019-04-29 16:23 ` Eli Zaretskii
2019-04-29 19:21 ` Mattias Engdegård
2019-04-29 19:56 ` Michael Albinus
2019-04-30 21:09 ` Mattias Engdegård
2019-05-01 17:45 ` Eli Zaretskii
2019-05-01 19:41 ` Mattias Engdegård
2019-05-02 12:18 ` Michael Albinus
2019-05-02 12:53 ` Mattias Engdegård
2019-05-02 13:02 ` Michael Albinus
2019-05-03 12:00 ` Mattias Engdegård
2019-05-03 13:44 ` Eli Zaretskii
2019-05-03 14:47 ` Mattias Engdegård
2019-05-04 9:04 ` Eli Zaretskii
2019-05-04 11:21 ` Mattias Engdegård
2019-05-04 13:41 ` Eli Zaretskii
2019-05-04 16:53 ` Michael Albinus
2019-05-04 17:08 ` Eli Zaretskii
2019-05-04 18:50 ` Mattias Engdegård
2019-05-04 19:43 ` Michael Albinus
2019-05-04 20:31 ` Michael Albinus
2019-05-04 20:46 ` Mattias Engdegård
2019-05-05 8:22 ` Michael Albinus
2019-05-05 9:58 ` Mattias Engdegård
2019-05-08 8:34 ` Mattias Engdegård
2019-05-08 8:47 ` Eli Zaretskii
2019-05-08 10:18 ` Mattias Engdegård
2019-05-08 10:58 ` Eli Zaretskii
2019-05-08 11:48 ` Mattias Engdegård
2019-05-08 12:35 ` Eli Zaretskii
2019-05-08 12:58 ` Mattias Engdegård
2019-05-08 13:09 ` Michael Albinus
2019-05-08 13:28 ` Eli Zaretskii
2019-05-08 14:13 ` Mattias Engdegård
2019-05-08 17:24 ` Eli Zaretskii
2019-05-08 18:17 ` Michael Albinus
2019-05-09 11:50 ` Michael Albinus
2019-05-10 15:22 ` Mattias Engdegård
2019-05-12 8:48 ` Michael Albinus
2019-05-12 19:49 ` Mattias Engdegård
2019-05-13 13:35 ` Michael Albinus
2019-05-14 12:41 ` Mattias Engdegård
2019-05-14 14:52 ` Michael Albinus
2019-05-08 10:23 ` Mattias Engdegård
2019-05-09 10:00 ` Mattias Engdegård
2019-05-09 10:48 ` Eli Zaretskii
2019-05-09 11:15 ` Mattias Engdegård
2019-05-10 9:49 ` Michael Albinus
2019-05-10 12:27 ` Mattias Engdegård
2019-05-10 12:43 ` Michael Albinus
2019-05-13 11:34 ` Mattias Engdegård
2019-05-13 15:08 ` Michael Albinus
2019-05-18 17:39 ` Mattias Engdegård
2019-05-19 9:12 ` Michael Albinus
2019-05-19 20:25 ` Mattias Engdegård
2019-05-20 7:30 ` Michael Albinus
2019-05-20 19:19 ` Mattias Engdegård
2019-04-29 7:19 ` Michael Albinus
2019-04-29 11:54 ` Mattias Engdegård
2019-04-29 12:26 ` Michael Albinus
2019-04-29 18:58 ` Mattias Engdegård
2019-04-29 20:04 ` Michael Albinus
2019-04-30 15:14 ` Eli Zaretskii
2019-04-24 19:59 ` Michael Albinus
2019-04-25 9:58 ` Mattias Engdegård
2019-04-25 11:04 ` Michael Albinus
2019-04-25 15:22 ` Mattias Engdegård
2019-04-30 1:03 ` Zhang Haijun
2019-04-30 7:06 ` Michael Albinus
2019-05-01 2:17 ` Zhang Haijun
2019-05-01 2:59 ` Zhang Haijun
2019-05-01 3:10 ` Zhang Haijun
2019-05-02 12:30 ` Michael Albinus
2019-05-02 13:24 ` Zhang Haijun
2019-05-02 12:28 ` Michael Albinus
2019-05-02 12:24 ` Michael Albinus
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BB3D2DC1-0C12-44F6-87D3-03CA878ED69E@acm.org \
--to=mattiase@acm.org \
--cc=35418@debbugs.gnu.org \
--cc=michael.albinus@gmx.de \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.