[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#51094: Check if run-with{-idle,}-timer needs to create a timer
From: |
Philip Kaludercic |
Subject: |
bug#51094: 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'
0001-Avoid-creating-timer-if-possible.patch
Description: Text Data
--
Philip Kaludercic
bug#51094: Check if run-with{-idle, }-timer needs to create a timer, Eli Zaretskii, 2021/10/08