emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#51094: closed (Check if run-with{-idle,}-timer needs to create a tim


From: GNU bug Tracking System
Subject: bug#51094: closed (Check if run-with{-idle,}-timer needs to create a timer)
Date: Fri, 08 Oct 2021 11:34:02 +0000

Your message dated Fri, 08 Oct 2021 11:33:27 +0000
with message-id <878rz37nug.fsf@posteo.net>
and subject line Re: bug#51094: Check if run-with{-idle, }-timer needs to 
create a timer
has caused the debbugs.gnu.org bug report #51094,
regarding Check if run-with{-idle,}-timer needs to create a timer
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
51094: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=51094
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: Check if run-with{-idle,}-timer needs to create a timer Date: Fri, 08 Oct 2021 09:36:22 +0000
Tags: patch


I have seen a few packages use run-with-timer or run-with-idle-timer,
where the SECS parameter is configurable with a user option. When this
timer doesn't repeat itself and it makes sense to set SECS to 0 when you
want something to run immediately, I don't think it makes sense to
create a timer object.

The following patch would remove this overhead, and calls the function
immediately if it makes sense.

Comparing these two test cases

--8<---------------cut here---------------start------------->8---
(benchmark-run-compiled 10000
  (funcall #'message "Test %s" "case"))

(benchmark-run-compiled 10000
  (run-with-timer 0 nil #'message "Test %s" "case"))
--8<---------------cut here---------------end--------------->8---

it turns out that funcall takes longer, but run-with-timer (or
run-with-idle-timer for that matter) block Emacs for significantly
longer.  Now this is a very forced example, because run-with-timer is
usually not called in a loop, but it do think it demonstrates a general
advantage.

In GNU Emacs 28.0.60 (build 6, x86_64-pc-linux-gnu, X toolkit, cairo version 
1.16.0, Xaw scroll bars)
 of 2021-10-05 built on icterid
Repository revision: 1cd1b2835b5e35562c677c48dcf185bb73af4275
Repository branch: emacs-28
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-native-compilation --with-x-toolkit=lucid
 --with-imagemagick 'CFLAGS=-O2 -march=native -pipe' LDFLAGS=-flto'

Attachment: 0001-Avoid-creating-timer-if-possible.patch
Description: Text Data

-- 
        Philip Kaludercic

--- End Message ---
--- Begin Message --- Subject: Re: bug#51094: Check if run-with{-idle, }-timer needs to create a timer Date: Fri, 08 Oct 2021 11:33:27 +0000
Lars Ingebrigtsen <larsi@gnus.org> writes:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Yes, the semantics of running things from a timer are different from
>> running them in the normal flow, so we can't transform 0-delay timers
>> into funcalls.
>
> See for instance:
>
>   (when (> (minibuffer-depth) 0)
>     ;; We're inside a minibuffer already, so if the emacs-client is trying
>     ;; to open a frame on a new display, we might end up with an unusable
>     ;; frame because input from that display will be blocked (until exiting
>     ;; the minibuffer).  Better exit this minibuffer right away.
>     (run-with-timer 0 nil (lambda () (server-execute-continuation proc)))
>
> So this change is a no go.

Ok, that makes sense.

One last question, would it make sense to provide a function like
run-with-timer that would work like my patch?

-- 
        Philip Kaludercic


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]