Hi Adam,
Thanks for picking this up again, and for offering to help fix it. I went back through the first thread with the source open, and I think we can now explain the whole chain. Even better, it ends in two small patches that would suit a first contribution.
Where the big file comes from
Your strace in July showed the 551,806-byte en_US.dic under tmp/sharedpresets/...richdocuments/wopi/settings.../wordbook/. That folder holds the shared settings that Nextcloud serves to Collabora Online. They are managed in Nextcloud’s Office admin settings, where an admin can upload custom dictionaries.
The upload code (browser/admin/src/integrator/WordBook.ts, wordbookValidation()) takes whatever text file it is given and adds a wordbook header (OOoUserDict1, lang: <none>, type: positive, ---) in front of it. It does not check that the file is really a word list. So if the hunspell en_US.dic from dict-en is uploaded there, it becomes a 49,568-entry wordbook, with the word count 49568 and the affix flags (0th/pt) kept as “words”. That matches the head output you posted exactly.
Why it costs 80 seconds
Every document load reads that wordbook. In engine/linguistic/source/dicimp.cxx, addEntry_Impl() runs this after inserting each word:
SAL_WARN_IF(!isSorted(), "linguistic", "dictionary entries unsorted");
isSorted() walks the whole list. Our Linux packages are built with --enable-sal-log, so the check runs even though the warning itself is filtered out by lokit_sal_log. With 49,568 words that is over a billion string comparisons: the O(n^2) you mentioned, and your pegged core. A real wordbook of a few dozen words never notices it.
Caolán’s typo fix from July (https://gerrit.collaboraoffice.com/c/online/+/8001) is in 26.04.3 and later, so your 26.04.5 already has it. It was a real bug, but not this one.
Fixing your server now
- In Nextcloud, open Administration settings, then Office, and look at the custom dictionaries in the Collabora settings section. Remove
en_US.dic, and any other hunspell dictionary that was uploaded there.
- If your Ansible role uploads it, drop that step. The hunspell dictionaries from
collaboraoffice-dict-* plus allowed_languages are all spell checking needs.
- Set
allowed_languages back to what you want, re-enable the jail (please do, the chroot is a security boundary), restart coolwsd and open a document.
To confirm the file is gone from a running jail:
ls -la /opt/cool/child-roots/*/tmp/sharedpresets/*/wordbook/
Each file there should be a few hundred bytes, not hundreds of kilobytes.
I can’t yet explain why turning the jail off appeared to help, or why an empty allowed_languages hides the problem. If both go back to normal once the file is removed, I would not spend more time on them. If not, please post what you see.
The two patches
This is where we need your help, if you’d like to. Both changes are small, and you already understand the bug better than almost anyone:
- Engine, C++: in
engine/linguistic/source/dicimp.cxx, remove the isSorted() check that runs after every insert in addEntry_Impl(). loadEntries() already checks once after the whole file is read, so the warning still fires for a broken dictionary. This turns your 80 seconds into milliseconds even for a huge file.
- Admin page, TypeScript: in
browser/admin/src/integrator/WordBook.ts, make wordbookValidation() reject a hunspell .dic (a first line that is only a number, or many words containing /flags) with a clear message that says hunspell dictionaries are installed as packages. That stops the next admin from landing where you did.
How to send them:
Please post here how step 1 goes. If the load time drops, that confirms the whole chain, and you can name it as the reproducer in the commit message. You can also find us on Matrix in #cool-dev:matrix.org if you’d rather work through the patches live.
Thanks
Darshan