Repository navigation
perf(lucene): load Jieba dictionaries once per process - #486
Merged
Merged
Conversation
2 tasks done
Every Lucene global index reader and writer constructed its own cppjieba::Jieba, reloading about 11.6MB of dictionaries each time. A table-level full-text search creates one reader per shard, so every query paid this cost once per shard. After the table-level full-text search tests were added in apache#461, paimon-global-index-test on tsan-x86_64 grew from about 1400s to about 3500s and pushed the job past its 120-minute timeout. Add LuceneUtils::GetJieba(), which loads each dictionary directory once per process and shares a const segmenter with all readers and writers. Segmentation only calls const cppjieba methods, which keep no mutable state and are safe to call concurrently. The cache is keyed by the canonical absolute path, so a relative PAIMON_JIEBA_DICT_DIR resolves against the current working directory instead of reusing dictionaries loaded from another one, and a directory that cannot be resolved returns an IOError instead of aborting in cppjieba. Document how a relative directory is resolved and that dictionary changes take effect only after the process restarts. On tsan-x86_64, this cuts paimon-global-index-test from about 3500s to about 160s, and the job finishes in about an hour instead of timing out.
SteNicholas
force-pushed
the
PAIMON-404
branch
from
November 2, 2026 05:26
bc75925 to
5ce2921
Compare
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.
Purpose
Linked issue: #404 (follow-up of #461)
Since #461, the
tsan-x86_64job ofBuild and Testruns past its 120-minute timeout (run 41000500442):paimon-global-index-testgrew from about 1400s to about 3500s.Every
LuceneGlobalIndexReaderandLuceneGlobalIndexWriterconstructed its owncppjieba::Jieba, reloading about 11.6MB of dictionaries each time. A table-level full-text search creates one reader per shard, so every query paid this cost once per shard, and the table-level full-text search tests added in #461 run many such queries.This PR adds
LuceneUtils::GetJieba():std::shared_ptr<const cppjieba::Jieba>is shared by all Lucene index readers and writers. The lock is held while loading, so concurrent first callers wait for a single load.cppjiebamethods, which keep no mutable state and are safe to call concurrently.PAIMON_JIEBA_DICT_DIRis resolved against the current working directory instead of reusing dictionaries loaded from another one, and a directory that cannot be resolved returns anIOErrorinstead of aborting insidecppjieba.Measured on the fork CI of the first revision of this change (
cc54c144, before the path canonicalization):tsan-x86_64:paimon-global-index-testtsan-x86_64: whole jobtsan-aarch64:paimon-global-index-testTests
LuceneUtilsTest.TestGetJiebaSharesOneSegmenter: concurrent first callers on a fresh dictionary directory get one segmenter and segment correctly with it; after all callers release their references, the cache still holds the segmenter and returns it again.LuceneUtilsTest.TestGetJiebaResolvesRelativeDictionaryDir: an unresolvable relative directory returns an error; the same relative directory resolved from two working directories loads two isolated segmenters (a user word changes theCutresult of one of them); the absolute path returns the cached segmenter.LuceneGlobalIndexTestcases and the Lucene cases ofGlobalIndexTestcover the reader and writer paths.Validation:
pre-commitpassed on the changed files. The change was not built locally. On the fork, the first revision passed every completed job ofBuild and Test(includingtsan-x86_64,tsan-aarch64,asan-ubsan-x86_64andasan-ubsan-aarch64) andGcc 8 Test; CI of the current revision is pending.API and Format
No.
LuceneUtilsis internal; there are no changes underinclude/and no storage format or protocol changes.Documentation
No new feature. The description of
PAIMON_JIEBA_DICT_DIRindocs/source/user_guide/global_index.rstnow explains how a relative directory is resolved and that dictionary changes take effect only after the process restarts.Generative AI tooling
Generated-by: Claude Code (Claude Opus 5.5)
🤖 Generated with Claude Code