Subject: Re: bug#73855: [PATCH] * lisp/autorevert.el: Avoid reverting buffer in short time

From: Michael Albinus <[email-masked]>
Date: Sat, 19 Oct 2024 11:06:41 +0200

Lin Sun <[email-masked]> writes:

Hi Lin,

> Let's look at this case: the auto-revert-interval is 5, a writing
> happened 1 write / second, total 20 writings (in 20 seconds). The
> revert-handler run on: first time (T0), and then locks for 5 seconds;
> then T5 lock done, revert the buffer; then T6 reverts the and locks it
> again... The revert happened as below:
>
> T0...T5,T6...T11,T12...T17,T18...T23
>
> The T5,T6 are nearby, similar happened on T11,T12, and after each lock
> end, there is a revert executed nearby.
>
> This patch try to enhance the lock, then makes the revert happened on:
>
> T0...T5...T10...T15...
>
> That reduced loading on my local.

Thanks for explanation, now I understand the scenario.

Your patch makes sense. However, autorevert-tests fail now:

--8<---------------cut here---------------start------------->8---
# make -C test autorevert-tests
make: Entering directory '/home/albinus/src/emacs/test'
make[1]: Entering directory '/home/albinus/src/emacs/test'
  GEN      lisp/autorevert-tests.log
Running 7 tests (2024-10-19 11:02:58+0200, selector `(not (tag :unstable))')
Reverting buffer `emacs-test-zzmdD8-autorevert'
   passed  1/7  auto-revert-test00-auto-revert-mode (3.554035 sec)
(Shell command succeeded with no output)
Reverting buffer `auto-revert-testenE8rY-autorevert'
Reverting buffer `auto-revert-testOJVaub-autorevert'
   passed  2/7  auto-revert-test01-auto-revert-several-files (0.172674 sec)
Reverting buffer `emacs-test-IIR73t-autorevert'
   passed  3/7  auto-revert-test03-auto-revert-tail-mode (2.527101 sec)
Reverting buffer `tmp'
Reverting buffer `tmp'
   passed  4/7  auto-revert-test04-auto-revert-mode-dired (0.457824 sec)
Reverting buffer `emacs-test-i5RWpJ-autorevert'
Test auto-revert-test05-global-notify backtrace:
  signal(ert-test-failed (((should (equal (auto-revert-test--buffer-st
  ert-fail(((should (equal (auto-revert-test--buffer-string buf-2) "2-
  (if (unwind-protect (setq value-171 (apply fn-169 args-170)) (setq f
  (let (form-description-173) (if (unwind-protect (setq value-171 (app
  (let ((value-171 'ert-form-evaluation-aborted-172)) (let (form-descr
  (let* ((fn-169 #'equal) (args-170 (condition-case err (list (auto-re
  (progn (setq buf-1 (find-file-noselect file-1)) (auto-revert-test--i
  (unwind-protect (progn (setq buf-1 (find-file-noselect file-1)) (aut
  (let* ((auto-revert-use-notify t) (auto-revert-avoid-polling t) (was
  (progn (let* ((auto-revert-use-notify t) (auto-revert-avoid-polling
  (unwind-protect (progn (let* ((auto-revert-use-notify t) (auto-rever
  (let* ((coding-system-for-write nil) (temp-file (identity (make-temp
  (progn (let* ((coding-system-for-write nil) (temp-file (identity (ma
  (unwind-protect (progn (let* ((coding-system-for-write nil) (temp-fi
  (let* ((coding-system-for-write nil) (temp-file (identity (make-temp
  (progn (let* ((coding-system-for-write nil) (temp-file (identity (ma
  (unwind-protect (progn (let* ((coding-system-for-write nil) (temp-fi
  (let* ((coding-system-for-write nil) (temp-file (identity (make-temp
  (progn (customize-set-variable 'auto-revert-interval 0.1) (let* ((co
  (unwind-protect (progn (customize-set-variable 'auto-revert-interval
  (let ((auto-revert-interval-orig auto-revert-interval)) (unwind-prot
  #f(lambda () [t] (let ((value-147 (gensym "ert-form-evaluation-abort
  #f(compiled-function () #<bytecode 0x1e80ca290561ae1>)()
  handler-bind-1(#f(compiled-function () #<bytecode 0x1e80ca290561ae1>
  ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
  ert-run-test(#s(ert-test :name auto-revert-test05-global-notify :doc
  ert-run-or-rerun-test(#s(ert--stats :selector ... :tests ... :test-m
  ert-run-tests((not (tag :unstable)) #f(compiled-function (event-type
  ert-run-tests-batch((not (tag :unstable)))
  ert-run-tests-batch-and-exit((not (tag :unstable)))
  eval((ert-run-tests-batch-and-exit '(not (tag :unstable))) t)
  command-line-1(("-L" ":." "-l" "ert" "--eval" "(setq treesit-extra-l
  command-line()
  normal-top-level()
Test auto-revert-test05-global-notify condition:
    (ert-test-failed
     ((should (equal (auto-revert-test--buffer-string buf-2) "2-a")) :form
      (equal "" "2-a") :value nil :explanation
      (arrays-of-different-length 0 3 "" "2-a" first-mismatch-at 0)))
   FAILED  5/7  auto-revert-test05-global-notify (1.020224 sec) at lisp/autorevert-tests.el:451
Reverting buffer `emacs-test-cjR4uH-autorevert-2'
   passed  6/7  auto-revert-test06-write-file (0.136182 sec)
Reverting buffer `emacs-test-EnNjg7-autorevert'
Reverting buffer `emacs-test-EnNjg7-autorevert-0'
Reverting buffer `emacs-test-EnNjg7-autorevert-1'
Reverting buffer `emacs-test-EnNjg7-autorevert-2'
Reverting buffer `emacs-test-EnNjg7-autorevert-3'
Reverting buffer `emacs-test-EnNjg7-autorevert-4'
Reverting buffer `emacs-test-EnNjg7-autorevert-5'
Reverting buffer `emacs-test-EnNjg7-autorevert-6'
Reverting buffer `emacs-test-EnNjg7-autorevert-7'
Reverting buffer `emacs-test-EnNjg7-autorevert-8'
Reverting buffer `emacs-test-EnNjg7-autorevert-9'
   passed  7/7  auto-revert-test07-auto-revert-several-buffers (5.077571 sec)

Ran 7 tests, 6 results as expected, 1 unexpected (2024-10-19 11:03:12+0200, 14.040452 sec)

1 unexpected results:
   FAILED  auto-revert-test05-global-notify

make[1]: *** [Makefile:185: lisp/autorevert-tests.log] Error 1
make[1]: Leaving directory '/home/albinus/src/emacs/test'
make: *** [Makefile:251: lisp/autorevert-tests] Error 2
make: Leaving directory '/home/albinus/src/emacs/test'
--8<---------------cut here---------------end--------------->8---

Could you pls check what's up?

> Best Regards, Lin

Best regards, Michael.