fast-syntax-highlighting: Long freeze with man command on MacOS
When I use the man
command and hit space there is a 3-5 second pause before any input is registered, it happens irrespective of terminal emulator used. Man seems to be the only command it happens with. I am using the current version of MacOS.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 7
- Comments: 15 (1 by maintainers)
I did som digging on this.
Workaround
Anywhere in
.zshrc
, add this line:Explanation:
The lag is caused by calls to
whatis
, which the highlighter calls when highlightingwhatis
andman
commands.whatis
typically takes a few seconds or so to execute, so the terminal will be blocked for that time.The line above declares a function, which will have precedence over the system
whatis
command. The function returns immediately if called from within the syntax highlighter (by testing if variableTHEFD
exists, which happens to be present in the syntax highlighter where thewhatis
calls are made). Otherwise, e.g. when callingwhatis
from the terminal, the function dispatches the systemwhatis
command.Some more info for anyone trying to fix this
The
whatis
calls are made in file/:chroma/-whatis.ch
, function-fast-whatis-chroma-callback()
, asexec {THEFD}< <( [...] LANG=C whatis [...] )
. This command doesn’t block though. It however stores a file descriptor for the output of the command to$THEFD
. This file descriptor is read from in file/function-fast-zts-read-all
with thesysread
command - this is the call that will actually block.An easy quick-fix would be to simply disable syntax highlighting of the
man
andwhatis
commands for macOS.@lucax88x , @londbell My workaround is only expected to work for freezing behaviour when colorizing the
man
commands (and as a consequence, thewhatis
command).For any significant lags when other commands are colorized, there is probably something else that
fast-syntax-highlighting
does upon colorizing that specific command that is blocking for some time.To solve such problems, you could try to disable syntax highlighting entirely for that specific command, e.g. trying the suggestion by @Aloxaf above.
For anyone wanting to find a better fix
For anyone wanting to trouble-shoot lag when highlighting other commands than
man
/whatis
, to try to find a workaround that doesn’t involve disabling highlighting for that command, this is the best solution I found:Copy-paste the above to the terminal without the comments, otherwise
zsh
will yield an error for the#
's since we’re using the default shell options.Now check
zprof.txt
. It will list the executed functions ordered by execution time, with the longest-running first: this will have been numbered1)
byzprof
. The function indicated there will probably be some top-level function, so check the breakdown of1)
slightly further down. There you’ll see the specific highligter function that caused the lag.E.g. for the lagging
man
command:So: the lag (9 seconds) happened in the function
-fast-zts-read-all
, who’s break-down shows that it was the call to-fast-whatis-chroma-callback
that caused the lag. Hence, further investigation/profiling should be done on this function.Another workround is disable highlight for man command
unfortunately this plugin is REALLY slow in OSX, even with a m1pro max.
when I try to input something like
git checkout branch/
it starts freezing for full seconds
The workaround from @LeuschkeTressa did not fix it.
This issue also occurs on Ubuntu varieties (I’m using Kubuntu 23.04). 👍 to @LeuschkeTressa - his workaround does fix the
man
freezing for me.I switched to zsh-syntax-highlighting because it works for me.