Skip to content

fix: resolve MeCab parser cache invalidation causing 1.5s slowdown on… - #712

Open
chengxicx wants to merge 1 commit into
LuteOrg:developfrom
chengxicx:fix/mecab-cache-perf
Open

fix: resolve MeCab parser cache invalidation causing 1.5s slowdown on…#712
chengxicx wants to merge 1 commit into
LuteOrg:developfrom
chengxicx:fix/mecab-cache-perf

Conversation

@chengxicx

Copy link
Copy Markdown

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

… 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
chengxicx force-pushed the fix/mecab-cache-perf branch from f4543ff to 604f003 Compare July 24, 2026 17:29
@jzohrab

jzohrab commented Jul 24, 2026

Copy link
Copy Markdown
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.

@bemitc

bemitc commented Jul 25, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants