fix: resolve MeCab parser cache invalidation causing 1.5s slowdown on… - #712
Open
chengxicx wants to merge 1 commit into
Open
fix: resolve MeCab parser cache invalidation causing 1.5s slowdown on…#712chengxicx wants to merge 1 commit into
chengxicx wants to merge 1 commit into
Conversation
… Japanese page loads The JapaneseParser.is_supported() cache was being invalidated on every call because mecab_path from settings was empty but _old_mecab_path stored the auto-detected path, causing path_unchanged to be False. Each page load accessed language.parser ~85 times (once per token), and each call created a new MeCab() instance (~18ms each), totaling 1.5 seconds of avoidable overhead. Fix: reuse previously auto-detected path when settings path is empty, ensuring the cache stays valid across repeated calls. Also add auto-detection of common MeCab library paths for macOS/Linux. Performance: 1.5s -> 60ms per page load (25x improvement).
chengxicx
force-pushed
the
fix/mecab-cache-perf
branch
from
July 24, 2026 17:29
f4543ff to
604f003
Compare
Collaborator
|
Thanks @chengxicx -- this sounds like a good contribution, cheers! It's odd that I didn't have this issue when I was trying out my Japanese ... but things happen. I had a question around the auto-detect stuff. |
|
Maybe it would be worth it to split the final validation (via calling MeCab()) into an inner function so you can check the validity in the path fallback list when you walk the list. That way, you handle the possible (but unlikely) edge case where the file exists but it is corrupt, for a different architecture, or for some other reason doesn't work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The JapaneseParser.is_supported() cache was being invalidated on every call because mecab_path from settings was empty but _old_mecab_path stored the auto-detected path, causing path_unchanged to be False.
Each page load accessed language.parser ~85 times (once per token), and each call created a new MeCab() instance (~18ms each), totaling 1.5 seconds of avoidable overhead.
Fix: reuse previously auto-detected path when settings path is empty, ensuring the cache stays valid across repeated calls. Also add auto-detection of common MeCab library paths for macOS/Linux.
Performance: 1.5s -> 60ms per page load (25x improvement).