Issue Description
When using the Danish (da) dictionary, certain misspelled words cause spellbook::Dictionary::suggest() to take an extremely long time, effectively hanging the spell checker and causing high CPU usage in the LSP/editor integration.
The issue appears to be related to aggressive suffix/affix expansion and recursive suggestion generation in the Danish Hunspell dictionary.
The problem is reproducible outside the LSP/editor and can be isolated to a direct call to:
Profiling shows the time is spent deep inside:
spellbook::suggester::map_suggest_impl
spellbook::checker::strip_suffix_only
spellbook::aff::Affix<Sfx>::condition_matches
Other dictionaries are significantly faster:
| Dictionary |
Time |
| en_us |
~118ms |
| de |
~120ms |
| es |
~108ms |
| sv |
~281ms |
| fr |
~520ms |
| da |
20s+ / effectively hangs |
Operating System
macOS
Editor
Zed
Codebook Version
0.3.39
Configuration
Steps to Reproduce
- Configure Codebook with the Danish dictionary:
- Open a .toml file in Zed with Codebook enabled
- Add the following line:
- Wait for Codebook to mark gitleaks as a misspelled word
- Hover the misspelled word to trigger Code Actions / suggestions
- Observe that the Code Action menu never appears for the word
- Observe sustained high CPU usage from codebook-lsp via Activity Monitor
Expected Behavior
The Code Action menu should appear normally for misspelled words, even if no suggestions can be generated.
Suggestion generation should either:
- complete within a reasonable amount of time, or
- fail gracefully / time out without causing prolonged CPU usage in the background.
Actual Behavior
For affected words such as gitleaks, the Code Action menu never appears.
The editor itself remains usable, and Code Actions still work for other misspelled words. However, codebook-lsp appears to continue processing the suggestion request in the background, causing sustained high CPU usage.
In my case, the codebook-lsp process reached very high CPU usage while trying to generate suggestions for the affected word.
Code Sample
Log Output
Additional Context
The Danish dictionary used appears to come from:
Codebook currently appears to use a patched fork of the Danish dictionary (blopker/dictionaries), likely due to compatibility issues with spellbook parsing quoted entries containing / while using FLAG num.
The latest upstream Stavekontrolden dictionary (2.9.096) could not be parsed directly by spellbook without similar escaping fixes.
The issue appears specifically related to suffix/compound handling in the .aff rules.
Removing or heavily reducing suffix rules dramatically improves execution time.
This issue was originally discovered through the Codebook LSP integration in Zed, where hovering misspelled words such as:
would cause codebook-lsp CPU usage to spike heavily.
Issue Description
When using the Danish (
da) dictionary, certain misspelled words causespellbook::Dictionary::suggest()to take an extremely long time, effectively hanging the spell checker and causing high CPU usage in the LSP/editor integration.The issue appears to be related to aggressive suffix/affix expansion and recursive suggestion generation in the Danish Hunspell dictionary.
The problem is reproducible outside the LSP/editor and can be isolated to a direct call to:
Profiling shows the time is spent deep inside:
Other dictionaries are significantly faster:
Operating System
macOS
Editor
Zed
Codebook Version
0.3.39
Configuration
Steps to Reproduce
# .gitleaks.tomlExpected Behavior
The Code Action menu should appear normally for misspelled words, even if no suggestions can be generated.
Suggestion generation should either:
Actual Behavior
For affected words such as
gitleaks, the Code Action menu never appears.The editor itself remains usable, and Code Actions still work for other misspelled words. However,
codebook-lspappears to continue processing the suggestion request in the background, causing sustained high CPU usage.In my case, the
codebook-lspprocess reached very high CPU usage while trying to generate suggestions for the affected word.Code Sample
Log Output
Additional Context
The Danish dictionary used appears to come from:
Codebook currently appears to use a patched fork of the Danish dictionary (
blopker/dictionaries), likely due to compatibility issues withspellbookparsing quoted entries containing/while usingFLAG num.The latest upstream Stavekontrolden dictionary (
2.9.096) could not be parsed directly byspellbookwithout similar escaping fixes.The issue appears specifically related to suffix/compound handling in the
.affrules.Removing or heavily reducing suffix rules dramatically improves execution time.
This issue was originally discovered through the Codebook LSP integration in Zed, where hovering misspelled words such as:
would cause codebook-lsp CPU usage to spike heavily.