Repository navigation
perf(fts): reduce embedded Jieba startup time and memory use - #929
Open
egolearner wants to merge 4 commits into
Open
egolearner wants to merge 4 commits into
egolearner wants to merge 4 commits into
Conversation
Prepare the tokenizer pipeline at collection open and load the embedded dictionary on the first tokenizing read or write. Share the immutable base trie across pipelines while binding external dictionaries at open.
Generate trie level offsets and lexical row ranges alongside the precompiled dictionary. Build contiguous nodes from the shared dictionary entries on first use and keep cppjieba lookup semantics for both exact words and DAG edges.
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.
Opening a collection with an embedded Jieba FTS field currently loads the dictionary and builds a mutable trie during pipeline setup. This PR defers that work until the first operation that uses the tokenizer, then uses a precompiled dictionary and a shared read-only trie.
Implementation
Measurements
Historical read-only collection timings on Linux (host 191)
Both Release builds used the same one-document collection on an Intel Xeon Platinum 8369B, opened it read-only, and searched for
分词.mainat PR base (a26f8ab) · two RSS-probe runsThe two
mainvalues in each row are elapsed times between consecutive memory snapshots, in run order. Those intervals include reading process memory statistics. The probe took its next snapshot after 31 further queries. The PR values come from the dedicated latency probe with a warm filesystem cache. The probes used different timing boundaries, so these figures do not support a Linux speedup ratio. The matched macOS benchmark below measures both builds with the same timer.mainat PR baseThe historical Linux PR build used the code committed as
07ef4a1. The only later change at the PR head (e3f26b8) renamed a local variable to satisfy GCC's shadowing check.Read-only collection latency
The table compares the PR base with the PR head on macOS arm64, using Release builds of the C API. Both versions opened the same on-disk collection with one embedded Jieba FTS field and one document containing
中文分词技术. Each fresh process opened the collection read-only and searched twice for分词. Both queries had to return the expected document. Values are medians over 30 fresh processes per version, with alternating run order and a warm filesystem cache.a26f8ab)e3f26b8)The base initializes Jieba during open. The PR moves that cost to the first FTS query and reduces the time to the first result by 74%. The last row is measured end to end in each process.
Validation