Repository navigation
[6018] 优化段落折行算法:引入原子路径数组索引并避免单个字符无效断字 - #4711
Merged
Merged
Conversation
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.
问题描述
在大型长文档排版时,段落折行算法(
line_breaker)是排版耗时的主要瓶颈之一:line_breaker_rep使用hashmap<path, lb_info> best记录最优折行信息。在绝大多数情况下(包括绝大多数未断字词条和 CJK 单字符),断点位置均为原子路径path(i)。每次折行测试不仅产生大量单元素链表节点的堆分配,还产生频繁的哈希表查询(test_better内部对同一个 key 执行多达 4 次哈希表读写)。N(s) > 4判断是否尝试断字(break_string)。对于单字符的特殊字符或 CJK 统一表意字符(在内部编码中以<#xxxx>形式表示,长度为 7),单字符也被误判为长单词,导致对不可分割的单字符反复调用底层语言断字函数(如get_hyphens),并对单字符子路径反复查询哈希表。优化方案
end + 1的连续数组atom_best。对于原子路径直接以can_hyphenate_leaf判定,若叶子节点字符串属于单个<...>形式的独立字符或字符数break_string及子路径检索。性能测试
line_breaks总耗时由 14.6 秒 骤降至 3.6 秒,纯折行耗时减少 11.0 秒(提速 75%);