fix: reduce redundant work during chat and note startup

Avoid hidden activity renders, no-op message saves and attachment scans when pinning conversations. Reuse note body inspection and skip unchanged attachment reference writes while preserving recovery and cleanup behavior.

Skip unnecessary Markdown normalization and memoize subagent lookups without delaying live rich text. Add storage operation counts and real Electron rendering equivalence benchmarks; full-render speedup remains unproven.

Validation: 5397 tests passed, 84 skipped; typecheck passed. Lint passed excluding two existing untracked sidebar probe files.

Release note: Reduce repeated rendering and disk work during chat, conversation pinning and note startup while preserving existing content and interactions.
This commit is contained in:
mesalogo
2026-09-28 20:53:43 +08:00
parent 594222a2b5
commit 13ff182858
23 changed files with 1047 additions and 54 deletions
@@ -64,6 +64,10 @@ Main 先保存资产,再保存草稿或接受队列;消息、分支建立独
会话删除、项目删除及清空数据均核对引用,启动回收已无归属的记录和孤立 UUID 目录。
清理失败保留无引用数据库记录供下次重试,不回滚已接受的草稿。
引用保存按输入顺序去重并查询资产。已有引用的顺序、会话归属均相同,且资产无需从临时目录
转存时,直接返回,不重复开启写事务或删除、插入引用。空引用同样适用;顺序、归属或附件
发生变化时仍按原事务更新,临时资产仍须转存。
助手库 schema 39 标记新附件元数据,阻止旧客户端将其当旧格式读取;没有批量改写历史附件。
知识库 schema 13 新增 `metadata.parsedResultId` 表达式索引,结果按主键定位,不扫描全部文档。
知识库新结果先写入独立 resultId 目录,数据库正文/chunks 发布成功后替换引用,再清理旧目录。
+25
View File
@@ -1,5 +1,30 @@
# Magic Notes Progress
## 2026-09-28: Startup Body Read Reuse
Startup repair now reuses the asset references collected during revision
inspection, as described in [file reconciliation](./technical-design.md#schema-38-migration).
The persisted format and revision recovery rules are unchanged.
- Real temporary SQLite/filesystem fixture: 120 entries across 120 notes,
half rich text and half canvas, with 4,039,560 bytes of body JSON.
Five initializations each read 240 bodies before and 120 after the change.
Logical bytes read fell from 8,079,120 to 4,039,560 per initialization.
- Baseline durations were 148.23, 134.42, 131.06, 140.66 and 172.90 ms;
after durations were 136.89, 119.11, 116.41, 115.14 and 116.26 ms.
Medians were 140.66 and 116.41 ms. These Windows runs used warm filesystem
caches on a shared machine; they do not measure cold application startup.
- `npx vitest run src/main/magic-notes/magic-note-storage.test.ts src/main/assistant/assistant-database.test.ts src/main/assistant/assistant-storage-upgrade.test.ts src/main/assistant-storage-startup.test.ts tests/assistant-storage-worker.test.ts`
passed 154 tests. Coverage includes failed media inspection, missing/invalid
bodies, retained shared assets, revision mismatch recovery and migration.
- Full `npm test`: 5382 passed, 84 skipped, 3 failed. The failures were the
App question-round request wait and Electron note capture focus/layout waits.
All three passed in targeted reruns; the full run was not all green.
The capture rerun exercised production App/preload/IPC/SQLite and reopening.
- `npm run typecheck` passed. Full lint still reports 10 errors in the existing
untracked `sidebar-final-probe.ts` and `sidebar-final-run.mjs`; lint excluding
those two files passed. No provider calls were made for these storage benchmarks.
## 2026-09-27: Shared Destructive Button Styles
The draft discard Portal now receives the global `danger-solid` styles. The
@@ -173,7 +173,12 @@ empty content. Failed creates leave no accepted database membership; their
unaccepted files are removed on the next access or reopen.
After commit, reconciliation derives `note.json` from database membership and
scans all retained entry files before removing unreferenced assets. Manifest or
inspects all retained entry files before removing unreferenced assets. Startup
repair reads each current body once to inspect its revision and collect asset
references, then passes the complete per-note reference set to reconciliation.
If media inspection fails, cleanup uses its existing deferred retry path rather
than trusting a partial set. Revision mismatch recovery still hydrates the body;
legacy conversion still verifies its written content. Manifest or
GC failures log `console.warn` with the note ID and error and remain in an
in-memory retry set. Later database access retries; reopening derives cleanup
again from membership. These cleanup failures do not turn a committed save,
@@ -280,6 +280,44 @@
Renderer 堆内存。
- **验收:** 测试数据、运行步骤和原始结果可重复执行。
#### 2026-09-28 Measurement Evidence (Partial)
`npx vitest run tests/streaming-markdown.electron.test.ts` runs the real
MarkdownRenderer in Electron 43.2.0 / Chromium 150.0.7871.129. It compares the
original normalizer with fast paths that skip unchanged text, retaining live
Markdown, math, code and HTML behavior. It also measures a 102,400-byte answer
at six growing prefixes, alternating original/current execution order in the
same page, with one warm-up sweep and three measured sweeps (18 samples each).
| Measurement | Original | Current |
| --- | --- | --- |
| 100KiB growing-prefix render median, isolated run | 54.80 ms | 54.65 ms |
| Same run p95 | 95.50 ms | 106.10 ms |
| Growing-prefix render median, full-suite run | 53.50 ms | 53.10 ms |
| Same run p95 | 93.70 ms | 83.40 ms |
These development-mode measurements include synchronous React rendering, DOM
commit and style/layout, but exclude frame waiting and paint. With 18 samples,
nearest-rank p95 is the maximum sample. The results do not establish an overall
rendering improvement. Smaller 6.4-7.2K-character corpora do show lower normalizer
cost: prose median 33-34 microseconds to below 1 microsecond, and mixed math/code
median 32-35 to 16-20 microseconds. The production changes remain limited to this
preprocessing and memoizing unchanged subagent-derived collections. In the
four-subagent regression, initial render plus six updates builds the lookup map
once instead of seven times; block-dependent scans still run when blocks change.
Validation: 550 prefix normalization comparisons, 1,100 short-prefix DOM
comparisons and 24 long-prefix DOM comparisons passed. The real Electron
terminal-status probe covers cancellation, failure, retry and persistence via
three loopback model-stub requests; the Mermaid viewer covers nine scenarios
and ten PNG downloads. No external model calls were used for these probes.
Full `npm test` passed 459 files / 5,397 tests, with 11 files / 84 tests skipped.
Type checking and scoped lint passed. Full lint remains blocked by the existing
untracked sidebar-final probe files.
This is partial evidence for PERF-03, not completion: full-App input latency,
frame rate, heap measurements and 500KB/1MB scenarios remain unmeasured.
### PERF-04 流式更新合并
- **优先级 / 状态:** P1 / 待开始