Subject: bug#79375: Character rendering slowly

From: Eli Zaretskii <[email-masked]>
Date: Wed, 03 Sep 2025 15:46:05 +0300

> Date: Wed, 3 Sep 2025 17:04:41 +0900
> From:  Psionic K via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> Emacs is about one week old igc branch.
> 
> The humble character below was grinding my Emacs to a halt whenever
> the point is in a buffer where it's visible.  I chased it into
> libfontconfig with perf.
> 
> ▄▄▄▄▄
> 
> After reproducing in a bare Emacs, I figured it was worth a shot.  If
> it slows down Emasc movement in the buffer while reading this message,
> you have reproduced the issue already.

Doesn't happen here, but my Emacs doesn't use Fontconfig, so maybe it
isn't a surprise.

> Perf data pointing at libfontconfig being bothered by this character.
> 
>   29.05%  emacs  libfontconfig.so.1.15.0                         [.]
> __popcountdi2
>   15.17%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCharSetSubtractCount
>    8.18%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCharSetFindLeafForward
>    5.96%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCompare
>    5.86%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCompareValueList
>    4.90%  emacs  libfontconfig.so.1.15.0                         [.]
> FcStrCmpIgnoreCase
>    4.89%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCharSetIterSet
>    4.73%  emacs  libfontconfig.so.1.15.0                         [.]
> FcStrHashIgnoreBlanksAndCase
>    2.04%  emacs  libfontconfig.so.1.15.0                         [.]
> FcStrGlobMatch
>    1.61%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCompareNumber
>    1.06%  emacs  libfontconfig.so.1.15.0                         [.]
> FcValueCanonicalize
>    0.98%  emacs  libfontconfig.so.1.15.0                         [.]
> FcStrCmp
>    0.94%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCompareBool
>    0.88%  emacs  libfontconfig.so.1.15.0                         [.]
> FcHashTableFind
>    0.79%  emacs  libfontconfig.so.1.15.0                         [.]
> FcCompareRange

AFAICT, Emacs doesn't call directly any of these Fc* Fontconfig
functions that seem to be hot spots.  So it is hard to figure out how
do we end up calling them.  Would it be possible to show the call-tree
that leads to __popcountdi2 or FcCharSetSubtractCount, so that the
Emacs functions which lead to those could be identified?

Btw, I presume that Emacs on your system is capable of displaying this
character, i.e. that you have some font capable of displaying it, is
that right?

Btw2, do you see the slowdown in "emacs -Q" when this character is in
the buffer?

Thanks.