Subject: bug#73766: 30.0.91; (documentation 'pcase) can take several seconds

From: Eli Zaretskii <[email-masked]>
Date: Sat, 12 Oct 2024 12:22:13 +0300

> From: Yikai Zhao <[email-masked]>
> Date: Sat, 12 Oct 2024 16:02:04 +0800
> 
> When `lsp-mode` is loaded, `(documentation 'pcase)` can take several
> seconds to complete.
> 
> Apparently, it would iterate over all defined pcase macros (N), and for
> each of those, `help-fns-short-filename` would iterate over all items in
> `load-path` (M). Total time complexity is N*M.
> 
> In my case, N is about ~400 (defined in lsp-protocols.el) and M is about
> ~100 (I think it's a normal case?).
> 
> This is especially problematic since the `documentation` method can be
> invoked by eldoc, which affects the responsiveness during editing.
> 
> --
> 
> Here's my profiler result:
> 
>         2713  86% - timer-event-handler
>         2713  86%  - apply
>         2707  86%   - #<native-comp-function
> F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_12>
>         2707  86%    - eldoc-print-current-symbol-info
>         2707  86%     - eldoc--invoke-strategy
>         2707  86%      - eldoc-documentation-default
>         2707  86%       - #<native-comp-function
> F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_17>
>         2707  86%        - elisp-eldoc-funcall
>         2707  86%         - elisp-get-fnsym-args-string
>         2707  86%          - documentation
>         2707  86%           - pcase--make-docstring
>         2606  82%            - help-fns-short-filename
>         2598  82%             - file-relative-name
>          335  10%                file-remote-p
>           27   0%                string-prefix-p

Adding Stefan and João, in case they have some comments or
suggestions.