Subject: bug#26525: `sit-for' in Flyspell slows typing down, hogs 90% of CPU

From: Clément Pit-Claudel <[email-masked]>
Date: Sat, 15 Apr 2017 16:28:14 -0400

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.