emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-persist-write slow when pp-use-max-width is t
@ 2022-10-20 21:46 Michael Eliachevitch
  2022-10-21  4:09 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Eliachevitch @ 2022-10-20 21:46 UTC (permalink / raw)
  To: Org Mode

I was wondering why kill-emacs emacs takes over a minute and after some profiling I found out that the call to org-persist-write-all takes long when pp-use-max-width is set to t and pp-max-width is also set (in my case to t, the window-width), which enables line folding in pp. The pp-call happens in org-persist--write-elisp-file when it is called by org-persist-write:index with the pp-parameter set to t. Maybe it's clearer with the following excerpt of my CPU-profile:

       38009  96%      - org-persist-write-all
       38009  96%       - org-persist-write
       37703  95%        - mapcar
       37703  95%         - #<compiled 0x42bf9b75c0e2209>
       37703  95%          - org-persist-write:index
       37703  95%           - org-persist--write-elisp-file
       37703  95%            - pp
       37703  95%             - pp-to-string
       37703  95%              - pp-emacs-lisp-code
       37687  95%               + pp--insert-lisp

Setting pp-use-max-width to nil made the function call almost instantanteous.

I had enabled pp-use-max-width in the past when pretty-printing the results of interactive elisp sessions (like pp-eval-last-sexp). I didn't think this would affect how other packages would save their data and I didn't expect this would result in such a performance hit. Possibly this is not an issue with org-mode or pp but just my own mistake of not being aware that pp is used as a library by other packages and thus customizing its behaviour has global effects.

Not sure if the org mailing list is the best place to report this observation. What org could do is to use a let-binding to temporarily set pp-use-max-width to nil to disable line folding. Or do you think that some users might care that their cache files are formatted prettily according to their customization options?

If you think this is not an issue with org-mode, maybe I/we could forward this to the pp-maintainers, as it's in emacs core possibly to emacs-devel? I think at least a warning in the variable documentation about performance hits might have been helpful.

Best regards,
Michael Eliachevitch


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-persist-write slow when pp-use-max-width is t
  2022-10-20 21:46 org-persist-write slow when pp-use-max-width is t Michael Eliachevitch
@ 2022-10-21  4:09 ` Ihor Radchenko
  2022-10-21 15:11   ` Michael Eliachevitch
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2022-10-21  4:09 UTC (permalink / raw)
  To: Michael Eliachevitch; +Cc: Org Mode

Michael Eliachevitch <m.eliachevitch@posteo.de> writes:

> I was wondering why kill-emacs emacs takes over a minute and after some profiling I found out that the call to org-persist-write-all takes long when pp-use-max-width is set to t and pp-max-width is also set (in my case to t, the window-width), which enables line folding in pp. The pp-call happens in org-persist--write-elisp-file when it is called by org-persist-write:index with the pp-parameter set to t. Maybe it's clearer with the following excerpt of my CPU-profile:
>
>        38009  96%      - org-persist-write-all
>        38009  96%       - org-persist-write
>        37703  95%        - mapcar
>        37703  95%         - #<compiled 0x42bf9b75c0e2209>
>        37703  95%          - org-persist-write:index
>        37703  95%           - org-persist--write-elisp-file
>        37703  95%            - pp
>        37703  95%             - pp-to-string
>        37703  95%              - pp-emacs-lisp-code
>        37687  95%               + pp--insert-lisp
>
> Setting pp-use-max-width to nil made the function call almost instantanteous.
>
> I had enabled pp-use-max-width in the past when pretty-printing the results of interactive elisp sessions (like pp-eval-last-sexp). I didn't think this would affect how other packages would save their data and I didn't expect this would result in such a performance hit. Possibly this is not an issue with org-mode or pp but just my own mistake of not being aware that pp is used as a library by other packages and thus customizing its behaviour has global effects.
>
> Not sure if the org mailing list is the best place to report this observation. What org could do is to use a let-binding to temporarily set pp-use-max-width to nil to disable line folding. Or do you think that some users might care that their cache files are formatted prettily according to their customization options?
>
> If you think this is not an issue with org-mode, maybe I/we could forward this to the pp-maintainers, as it's in emacs core possibly to emacs-devel? I think at least a warning in the variable documentation about performance hits might have been helpful.

Thanks for reporting!
pp-max-width has been introduced in Emacs 29.
The fact that pp becomes too slow is likely something to be fixed before
the next Emacs release.

While we can work around this issue on Org side, I'd prefer to ask Emacs
developers first and see if they can come up with a fix.

I suggest you to file a bug report to Emacs.
You may provide the contents of your org-persist-index-file inside
org-persist-directory. AFAIU, it is what is taking a lot of time to
print.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-persist-write slow when pp-use-max-width is t
  2022-10-21  4:09 ` Ihor Radchenko
@ 2022-10-21 15:11   ` Michael Eliachevitch
  2023-01-20  8:48     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Eliachevitch @ 2022-10-21 15:11 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org Mode


> pp-max-width has been introduced in Emacs 29.
> The fact that pp becomes too slow is likely something to be fixed before
> the next Emacs release.

Good catch and I agree. I compile emacs from the master branch and probably discovered in the emacs-news which I check between upgrades and I probably customized it subsequently, even though I forgot about the customization later.

> While we can work around this issue on Org side, I'd prefer to ask Emacs
> developers first and see if they can come up with a fix.
>
> I suggest you to file a bug report to Emacs.
> You may provide the contents of your org-persist-index-file inside
> org-persist-directory. AFAIU, it is what is taking a lot of time to
> print.

I submitted a bug report where I attached the index file and a minimal example file which benchmarks running pp on it, with which I could reproduce my issue from emacs -Q:

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58687

Let's see what the emacs devs have to say about it.
--
Michael Eliachevitch
Public PGP Key: https://keyoxide.org/hkp/546908c782383ad0e7d894ec1b8f95c8125dce31


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-persist-write slow when pp-use-max-width is t
  2022-10-21 15:11   ` Michael Eliachevitch
@ 2023-01-20  8:48     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2023-01-20  8:48 UTC (permalink / raw)
  To: Michael Eliachevitch; +Cc: Org Mode

Michael Eliachevitch <m.eliachevitch@posteo.de> writes:

> I submitted a bug report where I attached the index file and a minimal example file which benchmarks running pp on it, with which I could reproduce my issue from emacs -Q:
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58687
>
> Let's see what the emacs devs have to say about it.

Since the slowdown has been acknowledged as a known problem to be fixed
in future, I have pushed a workaround for now.

Fixed, on bugfix.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=ecdb44204

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-20  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-20 21:46 org-persist-write slow when pp-use-max-width is t Michael Eliachevitch
2022-10-21  4:09 ` Ihor Radchenko
2022-10-21 15:11   ` Michael Eliachevitch
2023-01-20  8:48     ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).