Subject: bug#66512: 30.0.50; flymake with checkdoc slows down typing in large Elisp buffers

From: Eli Zaretskii <[email-masked]>
Date: Sat, 14 Oct 2023 13:20:48 +0300

> From: Visuwesh <[email-masked]>
> Cc: [email-masked]
> Date: Sat, 14 Oct 2023 14:59:29 +0530
> 
> [வெள்ளி அக்டோபர் 13, 2023] Eli Zaretskii wrote:
> 
> >>     1. src/emacs -Q
> >>     2. C-x C-f lisp/org/org.el RET
> >>     3. M-x flymake-mode RET
> >>     4. M-g i org-drag-line-forward RET
> >>     5. Move the point to be inside the docstring, and start typing away.
> >>        You should notice the latency sooner or later.
> >> 
> >> I can reproduce this in my fairly long init.el file too (~10k lines) and
> >> I was forced to turn off checkdoc for the typing to be bearable in my
> >> init.el file.
> >
> > Thanks.
> >
> > This report needs more info:
> >
> >   . the file you used which produces this slowdown
> 
> I used org.el in the example.
> 
> >   . the profile is not fully expanded (some functions have "+")
> >   . for more detailed profile, please load the relevant Lisp files as
> >     *.el (not *.elc), and repeat the profiling
> >   . if the slowdown is visible in "emacs -Q", the profile from that is
> >     more important than the one from your customized Emacs
> 
> Here's the fully expanded profile after evaluating the checkdoc.el
> library in emacs -Q.  I also attached the file written by
> profiler-report-write-profile too.

Thanks.  It looks like the hot spots are:

   . the call to checkdoc-defun-info
   . this snippet from checkdoc-this-string-valid-engine:

     (save-excursion
       (forward-line 1)
       (beginning-of-line)
       (if (and (< (point) e)
		(looking-at "\\([ \t]+\\)[^ \t\n]"))
	   (if (checkdoc-autofix-ask-replace (match-beginning 1)
					     (match-end 1)
                                             "Remove this whitespace?"
					     "")
	       nil
	     (checkdoc-create-error
	      "Second line should not have indentation"
	      (match-beginning 1)
	      (match-end 1)))))
   
The rest is taken by GC, AFAICT.