Subject: Re: bug#58687: 29.0.50; Enabling pp-use-max-width dramatically slows down formatting of large sexps like org-persist--index

From: Eli Zaretskii <[email-masked]>
Date: Thu, 12 Jan 2023 15:36:25 +0200

> Cc: [email-masked]
> From: Ihor Radchenko <[email-masked]>
> Date: Thu, 12 Jan 2023 11:27:35 +0000
> 
> Michael Eliachevitch <[email-masked]> writes:
> 
> > I attached a file with the value of my `org-persist--index` expression and a file with a benchmark where I run pp on it, which took me 25s when running it with emacs -Q. Until recently my org persist index was much longer, but I pruned it a bit back when I wasn't aware what exactly caused the slowdown.
> 
> I'd like to bump this bug.

Why?

> 1. Save the attached files to same folder
> 2. Open benchmark-pp-on-org-persist-index.el
> 3. M-x eval-buffer
> 
> Observed: (19.617422592 2 1.0353073050000035)
> Expected: `pp' not taking ~20sec to write 15k of elisp data.

Did you look at what pp.el does when pp-use-max-width is non-nil?  I
show a profile below, to make that clear.

The "regular" pp (when pp-use-max-width is nil) finishes almost
instantaneously in this case.

       40048  85% - command-execute
       40048  85%  - call-interactively
       40046  85%   - funcall-interactively
       40046  85%    - execute-extended-command
       40044  85%     - command-execute
       40044  85%      - call-interactively
       40044  85%       - funcall-interactively
       40044  85%        - eval-buffer
       40043  85%         - let
       40042  85%          - benchmark-call
       40041  85%           - #<lambda 0x5461c05f>
       40041  85%            - pp
       40041  85%             - pp-to-string
       40041  85%              - pp-emacs-lisp-code
       40028  85%               - pp--insert-lisp
       40028  85%                - pp--format-list
       40028  85%                 - pp--insert
       38710  82%                  - pp--insert-lisp
       38710  82%                   - pp--format-list
       38708  82%                    - pp--insert
       20781  44%                     - pp--insert-lisp
       20780  44%                      - pp--format-list
       20780  44%                       - pp--insert
       13619  28%                        - pp--indent-buffer
       13603  28%                         - lisp-indent-line
       12595  26%                          - lisp-ppss
        9763  20%                           - syntax-ppss
           6   0%                              #<compiled -0x163d6f700e816ab6>
           1   0%                              syntax-propertize