Subject: bug#69703: Ispell process restarted too often

From: Juri Linkov <[email-masked]>
Date: Sun, 10 Mar 2024 19:10:19 +0200

>> When different projects have different personal dictionaries
>> and flyspell mode is used, then ispell process is killed and restarted
>> almost on every key press.  This creates hundreds of hunspell processes
>> that soon fill all available memory.
>
> If the speller process is killed each time before starting a new one,
> how come there's more than just one running at any given time?  IOW,
> how come you have "hundreds of hunspell processes" in memory?  Does
> killing a hunspell process fail for some reason?

Actually, hundreds were when I tried to use buffer-local ispell-process
because then ispell-internal-change-dictionary didn't kill ispell-process
but ispell-init-process created new processes.

But with the default configuration there are "only" a dozen of processes.
I guess one process per buffer.  And this is even in case when ispell-process
is NOT buffer-local.  I noticed that all these processes are created
after loading the desktop buffers.

> And why are you saying "almost on every key press"? are different
> personal dictionaries defined for different portions of text in some
> way?  Otherwise, I'd expect hunspell to be restarted when you change
> buffers, whuch is hardly "on every key press".  Or what am I missing?

On every key press was only when trying to use buffer-local ispell-process.

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 ...
  ...

>> Is it possible to fix this?
>
> 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.