Repository navigation
perf(sessions): replace substring indexing with lazy metadata scans - #9823
Merged
allenxu09 merged 1 commit intoNov 21, 2026
Merged
Conversation
This was referenced Nov 21, 2026
funkpopo
approved these changes
Nov 21, 2026
funkpopo
left a comment
Collaborator
There was a problem hiding this comment.
非常干净的简化:用惰性小写元数据和按空白分片的字面子串过滤取代了 FlexSearch 的 full 全子串索引,在消除大量内存占用和切应用重建开销的同时代码反而更精简。
审查要点确认
- 惰性构建与按列表粒度复用 (
src/hooks/useSessionSearch.ts#L16-L56):空查询完全零开销;仅在首次非空搜索时按sessions列表构造一次小写索引文本,切换providerFilter或providerIds不再重建;多关键词跨字段匹配保留原有的字面子串与大小写不敏感语义。 - 消除重复排序与清理依赖 (
src/components/sessions/SessionManagerPage.tsx#L289-L300):由页面在合并元数据与正文命中结果后统一排序一次,并移除唯一的flexsearch依赖。 - 验证结果:在
mainmerge-tree 上本地实测通过pnpm typecheck、pnpm format:check、pnpm knip以及useSessionSearch.test.ts/SessionManagerPage.test.tsx(30/30),GitHub 前端检查与全部分片测试通过,予以批准。
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.
Human Note / 本人说明
索引算法,数据结构优化
Summary / 概述
会话页使用 FlexSearch 的 full 分词为 UUID 和路径生成大量子串索引,切换应用后重新构建;空查询还会在 Hook 和页面各排序一次。
改为首次非空搜索时准备每条会话的小写元数据字符串,按空白拆分关键词并要求每项均为字面子串。缓存只依赖完整 sessions,应用选择和可见应用筛选复用缓存;页面在元数据与正文结果合并后统一排序。移除唯一使用点及 FlexSearch 依赖。
Related Issue / 关联 Issue
本次性能审计第 1 项,无独立 Issue。
Screenshots / 截图
不适用,保留现有页面布局。
Validation / 验证
本机 Node 合成 3,000 条包含 UUID、路径和中文的元数据:原索引构建约 909 ms,保留堆增量约 108 MiB;小写字符串准备约 4 ms,两关键词线性扫描平均约 0.33 ms(200 次)。这些是本机样本,不是所有数据规模的时延保证。
30 项相关测试通过:新增惰性准备、切换应用复用、列表更新失效、多关键词跨字段匹配、中文、大小写、UUID、路径、字面标点和不重复排序的回归;已有 SessionManagerPage 测试全部通过。
node node_modules/vitest/vitest.mjs run --no-cache tests/hooks/useSessionSearch.test.ts tests/components/SessionManagerPage.test.tsxbun run typecheck、bun run format:check、git diff --check通过;Bun 执行 package.json 同名脚本,本机未安装 pnpm。补充组合验证:将 perf(sessions): replace substring indexing with lazy metadata scans #9823、perf(sessions): index short queries and isolate WAL readers #9827、perf(privacy): avoid Unicode copies and prune redundant scans #9826、perf(usage): index filters and select pooled medians in one scan #9825 基于
5a5111b0临时合并后,完整cargo test通过:5,122 项单元测试、222 项集成测试,11 项忽略;TypeScript、Prettier、cargo fmt --check和生产前端构建通过。该组合的前端全量运行有 4,294 项通过,2 项 PiProviderForm 用例超过默认 5 秒时限。原始
main(5a5111b0)上相同两项也超时;仅对本次复跑设置--testTimeout=15000后,两项均通过,未改仓库测试时限配置。Checklist / 检查清单