Subject: bug#77961: 31.0.50; Rendering HTML email is very slow since commit #eab14d68b2e72b9a6b8b0cc67c9667c2bfbed4f5

From: martin rudalics <[email-masked]>
Date: Wed, 23 Apr 2025 08:17:29 +0200

>>> Looking into reverse call tree (B), I see that
 >>>
 >>>          1874  33% + set-window-configuration
 >>>
 >>> takes 1/3 of CPU cycles. Looking into its source, it does deal with
 >>> glyph matrices. So, it is the suspect, judging from the submitted
 >>> profiler report.
 >>
 >> Thanks, indeed.
 >>
 >> Which I also find weird. Why is that done in the first place?
 >
 > If the comment in set-window-configuration before it messes with glyph
 > matrices doesn't answer this question, maybe Martin (CC'ed) can help us
 > understand the reason?

Do you mean the adjust_frame_glyphs call?  It's called whenever we may
have changed window sizes.  We could have 'set-window-configuration' use
checks similar to those from run_window_change_functions.  But such a
change would have to be done with considerable care: After all, an
accidentally missing call of 'window-size-change-functions' would be
hardly noticed.  The missing update of a glyph matrix would be much more
harmful.

'save-window-excursion' should be banned.  Its reminder

   BEWARE: Most uses of this macro introduce bugs.

is much too mild in my opinion.  AFAICT the first two calls in shr.el
could be avoided by using 'buffer-text-pixel-size'.  The one in
'shr-render-td-1' looks worse - since it calls 'shr-pixel-buffer-width'
it nests one 'save-window-excursion' call into another which is simply
evil.

martin