Skip to content

Implement single-dict fast-path for pure-union PrefixMatch subtrees - #1367

Merged
frankslin merged 1 commit into
BYVoid:masterfrom
frankslin:upstream-master
Jun 30, 2026
Merged

frankslin merged 1 commit into
BYVoid:masterfrom
frankslin:upstream-master

Conversation

@frankslin

@frankslin frankslin commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

When a dict group's entire subtree consists only of union groups and
leaf dicts (no short_circuit node anywhere), union is associative and
the tree is semantically equivalent to a single flat union of all its
leaves. A single LeafMatcher trie traversal finds the longest match
across every leaf, which equals the multi-trie result while eliminating
GroupMatcher dispatch and redundant trie walks.

Adds CanFlattenAsUnion (recursive predicate) and CollectAllLeafDicts
(leaf accumulator), wired into BuildMatcher as an early-exit fast-path
before the existing GroupMatcher construction.

When a dict group's entire subtree consists only of union groups and
leaf dicts (no short_circuit node anywhere), union is associative and
the tree is semantically equivalent to a single flat union of all its
leaves.  A single LeafMatcher trie traversal finds the longest match
across every leaf, which equals the multi-trie result while eliminating
GroupMatcher dispatch and redundant trie walks.

Adds CanFlattenAsUnion (recursive predicate) and CollectAllLeafDicts
(leaf accumulator), wired into BuildMatcher as an early-exit fast-path
before the existing GroupMatcher construction.
@frankslin frankslin changed the title Flatten union dict groups into a single LeafMatcher per conversion step Implement single-dict fast-path for pure-union PrefixMatch subtrees Jun 30, 2026
@frankslin

Copy link
Copy Markdown
Collaborator Author

經測試,三種輸入長度(7.7kb 44kb 630kb)s2t 均都有穩定的 16–22% 提升,且越長的輸入優勢越明顯。
多出的 init 開銷是 ~2ms(32.3ms vs 30.4ms),同一 config 只會 build 一次,進程生命周期內後續調用直接復用。

@frankslin
frankslin merged commit 0a80edc into BYVoid:master Jun 30, 2026
33 of 34 checks passed
@frankslin
frankslin deleted the upstream-master branch June 30, 2026 14:44
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.

1 participant