🟡 P2 | search.rs 文本搜索每次循环创建新子串 #43

Closed
opened 2026-06-06 12:33:03 +08:00 by wangdl · 1 comment
Owner

背景

search_text 中 lower[start..].find(&query) 每轮迭代分配新的 &str 切片。长文本多匹配时 O(n²) 内存分配。

修复方案

用 lower[start..].match_indices(&query) 或记录 char 偏移复用。

位置

crates/zx_document_core/src/search.rs:62-98

## 背景 search_text 中 lower[start..].find(&query) 每轮迭代分配新的 &str 切片。长文本多匹配时 O(n²) 内存分配。 ## 修复方案 用 lower[start..].match_indices(&query) 或记录 char 偏移复用。 ## 位置 crates/zx_document_core/src/search.rs:62-98
wangdl added this to the M6:Code Review 质量完善(2026-06-06) milestone 2026-06-06 12:33:03 +08:00
Author
Owner

审查结论 (2026-06-06)

结论

search_textlower[start..].find() 每次迭代创建新子串,在极长文档中可能有性能影响。但对于知识库场景的典型文本长度(<100KB),影响可忽略。

状态

P2 低优先级,暂不修改。必要时可改用 match_indices

## 审查结论 (2026-06-06) ### 结论 `search_text` 的 `lower[start..].find()` 每次迭代创建新子串,在极长文档中可能有性能影响。但对于知识库场景的典型文本长度(<100KB),影响可忽略。 ### 状态 ✅ P2 低优先级,暂不修改。必要时可改用 `match_indices`。
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/zhixi-document-runtime#43
No description provided.