GNU bug report logs - #26525
`sit-for' in Flyspell slows typing down, hogs 90% of CPU

Previous Next

Package: emacs;

Reported by: Clément Pit-Claudel <cpitclaudel <at> gmail.com>

Date: Sat, 15 Apr 2017 20:29:02 UTC

Severity: normal

Tags: unreproducible

To reply to this bug, email your comments to 26525 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Sat, 15 Apr 2017 20:29:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Clément Pit-Claudel <cpitclaudel <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 15 Apr 2017 20:29:03 GMT) Full text and rfc822 format available.

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

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: `sit-for' in Flyspell slows typing down, hogs 90% of CPU
Date: Sat, 15 Apr 2017 16:28:14 -0400
[Message part 1 (text/plain, inline)]
Hi bug-gnu-emacs,

I have attached a profile in which Flyspell's flyspell-check-word-p consumes 89% of CPU time while typing text in a buffer.  This seems to be due to a call to sit-for in flyspell-check-word-p.  What is this sit-for there for?

- flyspell-post-command-hook                                     6077  89%
 - flyspell-check-word-p                                         6073  89%
  - sit-for                                                      6067  89%
   - read-event                                                  3826  56%
    + redisplay_internal (C function)                             128   1%
    + timer-event-handler                                          91   1%
    + fstar-subp-filter                                             3   0%
   - redisplay                                                   2205  32%
    + redisplay_internal (C function)                             100   1%
  + flyspell-get-not-casechars                                      2   0%
 + flyspell-check-pre-word-p                                        4   0%
+ command-execute                                                 220   3%
+ ...                                                             131   1%
+ timer-event-handler                                             116   1%
+ redisplay_internal (C function)                                 114   1%
+ company-post-command                                            102   1%
+ flycheck-perform-deferred-syntax-check                            5   0%
+ eldoc-pre-command-refresh-echo-area                               3   0%
  sml/generate-position-help                                        1   0%

I haven't spent much time investigating this issue yet, and my current repro isn't exactly reliable, but I was hoping that someone might be able to provide insight into Flyspell's behaviour before I dive to deep :) I did verify that disabling Flyspell fixed the issue.

Thanks!
Clément.
[flyspell.prof (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Sat, 15 Apr 2017 20:35:01 GMT) Full text and rfc822 format available.

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

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: 26525 <at> debbugs.gnu.org
Subject: Re: `sit-for' in Flyspell slows typing down, hogs 90% of CPU
Date: Sat, 15 Apr 2017 16:33:56 -0400
The relevant piece of code seems to be this:

      (cond
       ((get this-command 'flyspell-deplacement)
	(not (eq flyspell-previous-command this-command)))
       ((get this-command 'flyspell-delayed)
	;; The current command is not delayed, that
	;; is that we must check the word now.
	(and (not unread-command-events)
	     (sit-for flyspell-delay)))
       (t t)))

But the condition and the comment seem at odds, and it doesn't say much about why it calls `sit-for`.

Clément.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Mon, 17 Apr 2017 07:14:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down,
 hogs 90% of CPU
Date: Mon, 17 Apr 2017 10:14:17 +0300
> From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
> Date: Sat, 15 Apr 2017 16:33:56 -0400
> 
> The relevant piece of code seems to be this:
> 
>       (cond
>        ((get this-command 'flyspell-deplacement)
> 	(not (eq flyspell-previous-command this-command)))
>        ((get this-command 'flyspell-delayed)
> 	;; The current command is not delayed, that
> 	;; is that we must check the word now.
> 	(and (not unread-command-events)
> 	     (sit-for flyspell-delay)))
>        (t t)))
> 
> But the condition and the comment seem at odds, and it doesn't say much about why it calls `sit-for`.

I'm not quite sure what needs to be explained.  I think the doc string
of flyspell-delay and flyspell-default-delayed-commands tell the whole
story; if something is unclear there, please say what is unclear.

If you want to see this feature in action, turn on Flyspell, then type
something like "ssss", and then wait _without_ typing any non-word
character.  You will see that the mis-spelled word is marked only
after 3 sec, the default value of flyspell-delay.  Then contrast that
with the same word with a space typed after it.

IOW, this is a feature designed to avoid annoying users who type
slowly or make short breaks after typing only part of a word.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Mon, 17 Apr 2017 13:30:03 GMT) Full text and rfc822 format available.

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

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of
 CPU
Date: Mon, 17 Apr 2017 09:29:20 -0400
On 2017-04-17 03:14, Eli Zaretskii wrote:
>> But the condition and the comment seem at odds, and it doesn't say much about why it calls `sit-for`.
> 
> I'm not quite sure what needs to be explained.  I think the doc string
> of flyspell-delay and flyspell-default-delayed-commands tell the whole
> story; if something is unclear there, please say what is unclear.

The code reads (cond ((get this-command 'flyspell-delayed) …)), but the comment says "The current command is not delayed".  Does a non-nil flycheck-delayed really mean that the command is *not* delayed?

> If you want to see this feature in action, turn on Flyspell, then type
> something like "ssss", and then wait _without_ typing any non-word
> character.  You will see that the mis-spelled word is marked only
> after 3 sec, the default value of flyspell-delay.  Then contrast that
> with the same word with a space typed after it.

Thanks! I don't expect that this feature is intended to slow down typing, though, right?  In the example I posted it makes typing painfully slow.

Clément.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Mon, 17 Apr 2017 14:26:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of
 CPU
Date: Mon, 17 Apr 2017 17:25:30 +0300
> Cc: 26525 <at> debbugs.gnu.org
> From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
> Date: Mon, 17 Apr 2017 09:29:20 -0400
> 
> On 2017-04-17 03:14, Eli Zaretskii wrote:
> >> But the condition and the comment seem at odds, and it doesn't say much about why it calls `sit-for`.
> > 
> > I'm not quite sure what needs to be explained.  I think the doc string
> > of flyspell-delay and flyspell-default-delayed-commands tell the whole
> > story; if something is unclear there, please say what is unclear.
> 
> The code reads (cond ((get this-command 'flyspell-delayed) …)), but the comment says "The current command is not delayed".  Does a non-nil flycheck-delayed really mean that the command is *not* delayed?

I think the comment should be moved 2 lines below its current place,
that's all.

> > If you want to see this feature in action, turn on Flyspell, then type
> > something like "ssss", and then wait _without_ typing any non-word
> > character.  You will see that the mis-spelled word is marked only
> > after 3 sec, the default value of flyspell-delay.  Then contrast that
> > with the same word with a space typed after it.
> 
> Thanks! I don't expect that this feature is intended to slow down typing, though, right?  In the example I posted it makes typing painfully slow.

I didn't see any example in your OP, only a profile.  What did I miss?

And no, this is not supposed to slow down typing in any significant
way, as long as you type, because sit-for is supposed to return as
soon as input is available.  Your complaint was about CPU usage, not
about time delays, AFAIU.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Mon, 17 Apr 2017 15:37:01 GMT) Full text and rfc822 format available.

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

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of
 CPU
Date: Mon, 17 Apr 2017 11:36:45 -0400
On 2017-04-17 10:25, Eli Zaretskii wrote:
>> Thanks! I don't expect that this feature is intended to slow down typing, though, right?  In the example I posted it makes typing painfully slow.
> I didn't see any example in your OP, only a profile.  What did I miss?
> 
> And no, this is not supposed to slow down typing in any significant
> way, as long as you type, because sit-for is supposed to return as
> soon as input is available.  Your complaint was about CPU usage, not
> about time delays, AFAIU.

Indeed, there was only a profile; I don't have a good repro yet.  In that case, flyspell was slowing things down a lot, and the complaint was indeed about delays.
Sorry for being unclear.

Clément.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Tue, 17 Oct 2017 12:09:01 GMT) Full text and rfc822 format available.

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

From: Damien Cassou <damien <at> cassou.me>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down,
 hogs 90% of CPU
Date: Tue, 17 Oct 2017 14:07:58 +0200
> I have attached a profile in which Flyspell's flyspell-check-word-p
> consumes 89% of CPU time while typing text in a buffer. […]

This happened to me in the past then stopped for months. Now it happens
again and is really annoying. Emacs regularly freezes for around 5
seconds when I manipulate text.

-- 
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Thu, 13 Aug 2020 01:42:01 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down,
 hogs 90% of CPU
Date: Wed, 12 Aug 2020 18:41:18 -0700
Clément Pit-Claudel <cpitclaudel <at> gmail.com> writes:

> On 2017-04-17 10:25, Eli Zaretskii wrote:
>>> Thanks! I don't expect that this feature is intended to slow down typing, though, right?  In the example I posted it makes typing painfully slow.
>> I didn't see any example in your OP, only a profile.  What did I miss?
>>
>> And no, this is not supposed to slow down typing in any significant
>> way, as long as you type, because sit-for is supposed to return as
>> soon as input is available.  Your complaint was about CPU usage, not
>> about time delays, AFAIU.
>
> Indeed, there was only a profile; I don't have a good repro yet.  In that case, flyspell was slowing things down a lot, and the complaint was indeed about delays.
> Sorry for being unclear.

That was 3 years ago.  Are you still seeing this on a recent version of
Emacs, such as the recently released 27.1?

Best regards,
Stefan Kangas




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Fri, 28 Aug 2020 11:50:01 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Damien Cassou <damien <at> cassou.me>
Cc: Clément Pit-Claudel <cpitclaudel <at> gmail.com>,
 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down,
 hogs 90% of CPU
Date: Fri, 28 Aug 2020 04:49:08 -0700
Damien Cassou <damien <at> cassou.me> writes:

>> I have attached a profile in which Flyspell's flyspell-check-word-p
>> consumes 89% of CPU time while typing text in a buffer. […]
>
> This happened to me in the past then stopped for months. Now it happens
> again and is really annoying. Emacs regularly freezes for around 5
> seconds when I manipulate text.

That was 3 years ago.  Are you still seeing this on a recent version of
Emacs, such as the recently released 27.1?

Best regards,
Stefan Kangas




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Fri, 28 Aug 2020 12:37:02 GMT) Full text and rfc822 format available.

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

From: Damien Cassou <damien <at> cassou.me>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: Clément Pit-Claudel <cpitclaudel <at> gmail.com>,
 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of
 CPU
Date: Fri, 28 Aug 2020 14:35:58 +0200
Stefan Kangas <stefan <at> marxist.se> writes:
> That was 3 years ago.  Are you still seeing this on a recent version of
> Emacs, such as the recently released 27.1?

This hasn't happened for some time.

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Fri, 28 Aug 2020 18:41:02 GMT) Full text and rfc822 format available.

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

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Damien Cassou <damien <at> cassou.me>, Stefan Kangas <stefan <at> marxist.se>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of
 CPU
Date: Fri, 28 Aug 2020 14:40:07 -0400
On 8/28/20 8:35 AM, Damien Cassou wrote:
> Stefan Kangas <stefan <at> marxist.se> writes:
>> That was 3 years ago.  Are you still seeing this on a recent version of
>> Emacs, such as the recently released 27.1?
> 
> This hasn't happened for some time.
> 

There was a report of a similar issue on reddit recently, but it hasn't happened to me of late.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Sat, 29 Aug 2020 16:28:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>, 
 Damien Cassou <damien <at> cassou.me>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down,
 hogs 90% of CPU
Date: Sat, 29 Aug 2020 09:27:29 -0700
tags 26525 + unreproducible
thanks

Clément Pit-Claudel <cpitclaudel <at> gmail.com> writes:

> On 8/28/20 8:35 AM, Damien Cassou wrote:
>> Stefan Kangas <stefan <at> marxist.se> writes:
>>> That was 3 years ago.  Are you still seeing this on a recent version of
>>> Emacs, such as the recently released 27.1?
>>
>> This hasn't happened for some time.
>>
>
> There was a report of a similar issue on reddit recently, but it hasn't happened to me of late.

You wouldn't happen to have a link to the relevant thread?  I tried
searching the web but couldn't find anything.

I'm marking this bug as unreproducible for now.  Please report back if
you see this again or can provide any more information.




Added tag(s) unreproducible. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Sat, 29 Aug 2020 16:28:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Sat, 29 Aug 2020 18:11:01 GMT) Full text and rfc822 format available.

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

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Stefan Kangas <stefan <at> marxist.se>, Damien Cassou <damien <at> cassou.me>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of
 CPU
Date: Sat, 29 Aug 2020 14:10:01 -0400
On 8/29/20 12:27 PM, Stefan Kangas wrote:
> You wouldn't happen to have a link to the relevant thread?  I tried
> searching the web but couldn't find anything.

https://www.reddit.com/r/emacs/comments/i96lbo/flyspell_consuming_most_of_my_resources_why_oo/ , sorry for not including it the first time.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Wed, 02 Sep 2020 23:17:02 GMT) Full text and rfc822 format available.

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

From: Nick H <nick <at> tenpoint.co.nz>
To: stefan <at> marxist.se
Cc: Damien Cassou <damien <at> cassou.me>,
 Clément Pit-Claudel <cpitclaudel <at> gmail.com>,
 26525 <at> debbugs.gnu.org
Subject: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of CPU
Date: Thu, 03 Sep 2020 11:15:50 +1200
> I'm marking this bug as unreproducible for now.  Please report back
> if you see this again or can provide any more information.

I just bumped into this bug on 27.1 with the same symptoms - typing lag
after activating flyspell-mode. 

I took a couple of profiles - the first when lag was apparent and
another after clearing the lag by toggling flyspell-mode.

Both profiles show a similar result, so the "high cpu" in sit-for might
be a red-herring.

Profile 1 - with lag
  - flyspell-post-command-hook                     1146  92%
   - flyspell-check-word-p                         1120  90%
    - sit-for                                      1117  90%
     - redisplay                                    551  44%
      + redisplay_internal (C function)               1   0%
       read-event                                   390  31%
    - flyspell-get-not-casechars                      1   0%
       ispell-get-decoded-string                      1   0%
   + flyspell-word                                    8   0%
   + flyspell-check-pre-word-p                        3   0%
  + command-execute                                  65   5%
  + ...                                              22   1%
  + undo-auto--add-boundary                           1   0%

Profile 2 - without lag
  - flyspell-post-command-hook                     3507  94%
   - flyspell-check-word-p                         3432  92%
    - sit-for                                      3414  92%
     - redisplay                                   1660  44%
      + redisplay_internal (C function)               3   0%
     + read-event                                  1317  35%
    + ispell-get-otherchars                           6   0%
    + flyspell-get-not-casechars                      5   0%
   + flyspell-word                                   17   0%
   + flyspell-check-pre-word-p                       13   0%
  + command-execute                                  93   2%
  + ...                                              87   2%
  + timer-event-handler                               3   0%
    undo-auto--add-boundary                           2   0%
    tooltip-hide                                      1   0%

Nick





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Thu, 03 Sep 2020 10:20:01 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Nick H <nick <at> tenpoint.co.nz>
Cc: Damien Cassou <damien <at> cassou.me>,
 Clément Pit-Claudel <cpitclaudel <at> gmail.com>,
 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down,
 hogs 90% of CPU
Date: Thu, 3 Sep 2020 03:19:10 -0700
Nick H <nick <at> tenpoint.co.nz> writes:

> I just bumped into this bug on 27.1 with the same symptoms - typing lag
> after activating flyspell-mode.

What is your ispell/flyspell configuration?

Do you have any ideas about how to reproduce it, or could you say
something about the circumstances under which you saw this?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26525; Package emacs. (Fri, 04 Sep 2020 01:02:02 GMT) Full text and rfc822 format available.

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

From: Nick Helm <nick <at> tenpoint.co.nz>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 26525 <at> debbugs.gnu.org
Subject: Re: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of
 CPU
Date: Fri, 04 Sep 2020 13:01:35 +1200
On Thu, 2020-09-03 at 03:19 -0700, Stefan Kangas wrote:
> Nick H <nick <at> tenpoint.co.nz> writes:
> 
> > I just bumped into this bug on 27.1 with the same symptoms - typing
> > lag after activating flyspell-mode.
> 
> What is your ispell/flyspell configuration?

Nothing unusual:

grep -C2 -E \(ispell\|flyspell\) ~/.config/emacs/init.el

  ; spelling
  (setq ispell-choices-win-default-height 2)
  (setq ispell-dictionary "en_NZ")
  (setq ispell-personal-dictionary (concat nh-etc "hunspell-dict"))
  (setq ispell-program-name "hunspell")
  (setq ispell-dictionary-alist
        '(("en_NZ" "[[:alpha:]]" "[^[:alpha:]]" "[']" t nil t utf-8)))
  (with-eval-after-load 'flyspell
    (progn
      (define-key 
         flyspell-mouse-map [down-mouse-3] #'flyspell-correct-word)
      (define-key 
         flyspell-mouse-map [mouse-3] nil)))

> Do you have any ideas about how to reproduce it, or could you say
> something about the circumstances under which you saw this?

The lead-up was pretty mundane - I visited an elisp file, set the 
region to a block of text, M-x write-region, C-x C-f the resulting
file, M-x vi-l-m, a few edits, M-x flys-buf, M-x flys-mod --> lag

I tried to reproduce the problem, but no success. Sorry.






Removed tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 30 Nov 2020 12:46:02 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 200 days ago.

Previous Next


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