GNU bug report logs - #76609
31.0.50; The 0.1s repeat timer is very CPU-intensive; it might be a bug?

Previous Next

Package: emacs;

Reported by: Eval Exec <execvy <at> gmail.com>

Date: Thu, 27 Feb 2025 13:57:02 UTC

Severity: normal

Found in version 31.0.50

Full log


Message #14 received at 76609 <at> debbugs.gnu.org (full text, mbox):

From: Eval Exec <execvy <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 76609 <at> debbugs.gnu.org
Subject: Re: bug#76609: 31.0.50; The 0.1s repeat timer is very CPU-intensive; 
 it might be a bug?
Date: Thu, 27 Feb 2025 22:38:35 +0800
Compare to a bash script:
while true; do
  sleep 0.1;
   date
done

above script have 0% CPU usage on my laptop.

change it to 0.0001:
while true; do
  sleep 0.0001;
   date
done

even 0.0001 s repeat, the bash script only have 4% cpu usage.

So I think a 0.1s repeat timer in Emacs consume 45% is very surprise.
I think maybe we should improve the timer performance

On Thu, Feb 27, 2025 at 10:34 PM Eval Exec <execvy <at> gmail.com> wrote:
>
> 45% CPU for a 0.1s repeating timer does seem surprisingly high. Is
> there a way we can optimize this, given the frequent timer
> invocations?
>
> On Thu, Feb 27, 2025 at 10:27 PM Eli Zaretskii <eliz <at> gnu.org> wrote:
> >
> > > From: Eval Exec <execvy <at> gmail.com>
> > > Date: Thu, 27 Feb 2025 21:55:40 +0800
> > >
> > > I a 0.1 s repeat timer in emacs -Q, then Emacs's the cpu usage is 30% ~
> > > 70%.
> > > I think it's a bug.
> >
> > I get around 45% with this, but why do you consider this a bug?  Your
> > timer function perhaps does nothing, but the timer machinery is
> > invoked every 100 msec, and it does consume CPU.
> >
> > in addition, when you have a high-frequency timer, the Emacs idle loop
> > is much more expensive, because instead of waiting inside pselect, it
> > runs all the loop code every 100 msec.
> >
> > Maybe I'm missing something, but I don't see a bug here.




This bug report was last modified 108 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.