Subject: bug#69703: Ispell process restarted too often

From: Juri Linkov <[email-masked]>
Date: Tue, 12 Mar 2024 09:45:14 +0200

>> I noticed that all these processes are created
>> after loading the desktop buffers.
>
> Please show a reproduction recipe, as I didn't know this is possible.

Here is what happens during loading the desktop:

1. When creating a new file buffer, 'ispell-kill-ispell' is called
   for every buffer because its personal dictionary is different
   from the previously restored buffer.

2. Then in the middle of 'ispell-kill-ispell',
   'project-mode-line-format' kicks in
   from 'redisplay_internal'.

3. 'project-mode-line-format' creates a temporary buffer
   and enables 'flyspell-mode' in it.

4. 'flyspell-mode' creates a new stray process.

5. 'ispell-kill-ispell' that was started at 1 above
   finishes killing the previous Ispell process.
   So the processes created by 'flyspell-mode' remain unhandled.

Ok, the bug is in 'project-mode-line-format'.
I will send a patch to fix it in a separate bug report.

>> But with the default configuration ispell-process is killed and started
>> "only" on switching buffers that is very annoying since most of the time
>> I see these messages in the echo area:
>> 
>>   Ispell process killed
>>   Starting new Ispell process /usr/bin/hunspell ...
>>   Ispell process killed
>>   Starting new Ispell process /usr/bin/hunspell ...
>>   Ispell process killed
>>   Starting new Ispell process /usr/bin/hunspell ...
>
> If the problem is with the messages, it can be easily solved by adding
> some optional feature.  But I understand there are more urgent issues,
> so let's discuss those first, okay?

Messages is not a problem.  Perpetual process restarting causes
noticeable performance degradation.

Since the bug will be fixed in 'project-mode-line-format',
the remaining problems are less urgent.

But still the remaining inconvenience is the following:

1. Loading the desktop takes more time since
it restarts the Ispell process for the every buffer:

Starting new Ispell process...
Ispell process killed
Starting new Ispell process...
Ispell process killed
Starting new Ispell process...
Ispell process killed
Starting new Ispell process...
Ispell process killed
Starting new Ispell process...

2. Ispell processes still restarted on editing another buffer.

>> > Not easily, AFAIR.  But I don't think I understand the nature of the
>> > problem you are experiencing, see above.
>> 
>> The nature of the problem is the inability of ispell.el to maintain
>> multiple processes with different dictionaries simultaneously
>> that is required by flyspell-mode.
>> 
>> What is needed here is a hash of processes where the key is
>> the ispell program name and its dictionary arguments.
>
> Feel free to submit patches for that, and thanks.  (But didn't you
> just complain about one speller process per buffer?)

Since implementing this is not urgent, here is a design outline
for possible future improvements:

1. Create a pool of Ispell processes.

2. Instead of killing Ispell processes
   just get the process from the pool
   by the ispell program name and its dictionary arguments.

3. For backward-compatibility in 'ispell-init-process'
   need to set the value of 'ispell-process' to the process
   extracted from the pool.