🟡 P2 | search.rs 文本搜索每次循环创建新子串 #43
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
背景
search_text 中 lower[start..].find(&query) 每轮迭代分配新的 &str 切片。长文本多匹配时 O(n²) 内存分配。
修复方案
用 lower[start..].match_indices(&query) 或记录 char 偏移复用。
位置
crates/zx_document_core/src/search.rs:62-98
审查结论 (2026-06-06)
结论
search_text的lower[start..].find()每次迭代创建新子串,在极长文档中可能有性能影响。但对于知识库场景的典型文本长度(<100KB),影响可忽略。状态
✅ P2 低优先级,暂不修改。必要时可改用
match_indices。