Hi Felix,
First of all, thanks for the easy-to-follow Emacs -Q reproduction
recipe. I reproduced the problem, although in my own test, which
used medium/small C++ files, the delay I noticed wasn't very long,
Which-function-mode relies on Imenu, which is the keeper of
a syntactic sub-tree of the file, which it must collect from somewhere.
When Eglot is enabled, Imenu gets its tree from the LSP server.
Depending on the LSP server and the amount of information at
hand, this can be a lot of information and take some time to gather.
It seems which-function-mode not only relies on Imenu but also
blocks the user interface and redisplay while it is waiting for the
Imenu backend to reply (the Imenu backend in this case being
Eglot's).
I don't see a good fix for this, except disabling Imenu/Eglot integration
by adding the symbol 'imenu to eglot-stay-out-of (see the Eglot
manual).
It can also be that what's slowing down operation here isn't the
collection of the syntax tree per se but the logging that is going
on. See also the Eglot manual for how to configure
eglot-events-buffer-size to see if it makes a difference or not.;
Finally, you can probably get some other source for Imenu information
to feed which-func-mode. The new C++ modes like c++-ts-mode seems
to have similar information handy, and perhaps it takes a lot less time
to compute.
João