vomebook commited on
Commit
9fbac22
·
1 Parent(s): f3f5d43

Clean Reader test and report artifacts

Browse files
DATABASE_OPTIMIZATION_REPORT.md DELETED
@@ -1,41 +0,0 @@
1
- # Index And Cache Optimization
2
-
3
- Date: 2026-09-18
4
-
5
- ## Changes
6
-
7
- - Publish ordered folder, repository, sort and random-selection postings as packed
8
- unsigned integer arrays. Existing query-order caches reuse precomputed arrays;
9
- corpus-wide iteration uses `range` instead of an intermediate list.
10
- - IndexedDB pruning deletes expired keys through the timestamp index and advances
11
- directly past retained entries. Visible recent pages share one write transaction.
12
- - Search semantics, complete results, ordering, cache capacities/TTLs, database
13
- version and saved-record schemas are preserved.
14
-
15
- ## Local Measurements
16
-
17
- The backend benchmark uses 50,000 synthetic records, not production memory readings.
18
- The deep size of the selected ordered-index structures (deduplicating shared objects
19
- within those structures) fell from 6,976,425 to 2,009,801 bytes, about 71%.
20
- This does not mean total service RSS fell by 71%; corpus strings and word indexes are
21
- outside this measurement. Eight query cases retained identical totals and complete
22
- ordered-index SHA-256 values. Cases include cold/repeated calls, page 1/page 2,
23
- exact/fuzzy search, repository/folder/extension filters and name/size ordering.
24
-
25
- For 20 controlled cache saves with full stores, cursor movements fell from 1,960
26
- to 80 (40 `continue` and 40 `advance` calls). The number of stored entries and
27
- content writes stayed the same. A separate two-visible-page case used one write
28
- transaction instead of two. Browser wall time is environment-dependent; this is
29
- not a real-phone or network-loading speed guarantee.
30
-
31
- ## Verification
32
-
33
- - Fast backend/API/security/static regression suite passed.
34
- - Packed-order sharing, rebuild invalidation and real-data Uvicorn integration passed.
35
- - Both sites passed 33 cache/position browser cases and 11 cache cases against
36
- minified app builds, including expiry boundaries, timestamp ties, old persisted
37
- pages, query/generation isolation and cross-page write batching.
38
- - Production acceptance compares pre/post-deploy IDs, exact totals and corpus
39
- generations; browser-local fixtures exercise actual deployed IndexedDB logic.
40
-
41
- Measurement and acceptance JSON: `/tmp/opencode/database-optimization/`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
READER_LOADING_REPORT.md DELETED
@@ -1,69 +0,0 @@
1
- # 阅读器加载测量与缓存升级验收
2
-
3
- 日期:2026-09-15。测量来源为生产 `https://voiceofml-search.hf.space/`,
4
- Space 版本 `667e98a54d777a05b4d81646e2e46a7ba973f9dd`。
5
- 本次预热可靠性与构建修复尚未部署时完成测量;阅读器渲染代码未改。
6
-
7
- ## 方法与范围
8
-
9
- - Chromium 无头浏览器,390×844 视口,未模拟手机 CPU 或限制网络。
10
- - 从生产 API 分别选择一个 1–200 KB 的 TXT、Markdown、原生 PDF,每种三组配对。
11
- - 每组首次打开使用新浏览器上下文并清除 HTTP 缓存;第二次保留 HTTP 缓存和阅读历史。
12
- - 禁用 Service Worker,直接打开仅带书籍 ID 的阅读器链接,无搜索页悬停预热。
13
- 数字不是搜索页点击耗时,也不是本次预热修复的前后速度对比。
14
- - 记录运行时启动、地址解析、格式 open/render、ready 和首次内容观察;PDF 等待页面渲染完成。
15
- - 通过临时浏览器包装器和 CDP 测量,无生产埋点、无安全策略修改。
16
- 阶段可能包含异步等待,CPU ScriptDuration 单独记录;各列中位数不应相加。
17
-
18
- ## 结果
19
-
20
- 单位:秒,三次中位数。
21
-
22
- | 格式 | 首次内容出现 | 缓存后再次出现 | 首次启动阶段 | 首次地址解析 | 首次内容/引擎准备 | 首次 render 阶段 |
23
- |---|---:|---:|---:|---:|---:|---:|
24
- | TXT | 8.578 | 0.111 | 7.761 | 0.320 | 0.444 | 0.010 |
25
- | Markdown | 10.052 | 0.921 | 7.754 | 0.353 | 1.822 | 0.030 |
26
- | PDF | 11.101 | 0.315 | 7.861 | 0.322 | 2.344 | 0.402 |
27
-
28
- 首次静态/引擎响应没有 CDP 缓存命中;二次观察到 12–14 个缓存响应。
29
- 缓存后的启动阶段中位数为 51–56 ms。
30
-
31
- 补充实验保留静态资源缓存,对阅读器 fetch 设置 `cache: reload`,重新请求地址和内容:
32
-
33
- | 格式 | 首次内容出现 | 启动阶段 | 地址解析 | 内容/引擎准备 | render | 主线程 ScriptDuration |
34
- |---|---:|---:|---:|---:|---:|---:|
35
- | TXT | 1.252 | 0.417 | 0.364 | 0.411 | 0.010 | 0.015 |
36
- | Markdown | 1.682 | 0.371 | 0.336 | 0.815 | 0.032 | 0.034 |
37
- | PDF | 1.513 | 0.429 | 0.350 | 0.676 | 0.066 | 0.039 |
38
-
39
- PDF.js 内部请求不完全受 window.fetch 包装器控制,PDF 补充实验不能排除所有正文缓存。
40
- 额外测量参数改变导航 URL,补充实验也重新请求 HTML。
41
-
42
- 样本:TXT《95%的强化接种率与自愿接种自相矛盾》;Markdown《打倒帝国主义和反动战争!无产阶级国际主义万岁!》;
43
- PDF《活页文选 11 葫芦僧判断葫芦案1》。未覆盖大书、EPUB、DOCX 或真实手机。
44
- 网络、CDN、TLS、服务器缓存和同机并行活动都会影响耗时,不能将这些值作为稳定 SLA。
45
-
46
- ## 判断
47
-
48
- 样本的首次等待主要在静态页面/脚本/样式加载和内容准备,主线程执行量明显小于等待时间。
49
- 保留现有资源预取即可,当前证据不支持增加默认隐藏阅读器初始化。
50
- 后续性能工作应先看 HF 静态资源瀑布和缓存命中,再判断是否调整加载安排。
51
-
52
- ## 旧缓存升级
53
-
54
- 用 `6629cf2` 旧 HTML、旧 app、旧 Service Worker 和同名 Cache Storage,模拟内容散列资源引用,
55
- 切换至本次构建产物,验证首次访问、更新 Worker、再次打开、断网获取缓存脚本及恢复联网。
56
- 另用旧 HTML 直接加载新版 app 复现缺失导航全局对象;构建时将导航依赖条件式打入 app 后通过。
57
- 缓存名固定 `voiceofml-search-hf-v1.0.0`。
58
- HF 原有导航请求绕过 Service Worker,断网时仅验证已缓存运行资源和已打开页面的可用性,
59
- 不宣称新增了离线整页重载支持。
60
-
61
- ## 本地复现材料
62
-
63
- - `node tests/test_reader_warming.js`
64
- - `python3 -B -m unittest tests.test_reader_navigation_host -v`
65
- - `/tmp/opencode/check_cache_upgrade.py hf`:真实旧 Worker 升级验收,需要 `/tmp/opencode/navigation-build-hf` 产物。
66
- - `/tmp/opencode/measure_reader_open.py hf [shell]`:只读生产计时,原始阶段数据位于
67
- `/tmp/opencode/reader-timing-hf.json` 和 `/tmp/opencode/reader-timing-hf-shell.json`。
68
-
69
- 临时材料为本机验收记录,不作为 Space 运行文件上传。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
SITE_OPTIMIZATION_REPORT.md DELETED
@@ -1,34 +0,0 @@
1
- # Site optimization acceptance — 2026-09-18
2
-
3
- HF search computations now run in one owned thread. At most 32 jobs are admitted;
4
- search caches remain serially owned, queued cancellation drops unused work, and
5
- cancelling a running request does not release the computation slot early. Shutdown
6
- drains owned work. Responses expose queue, search, Reader-assets and serialization
7
- durations through `Server-Timing`, without queries or paths.
8
-
9
- Paired local measurements used the checked-out 100,000-record snapshot and the exact
10
- wildcard query `*文*`, alternating the previous synchronous call and the threaded API
11
- three times each in one process, clearing both search caches before each call.
12
- All samples returned 18,972 records in total and identical first-page result hashes.
13
- These counts describe the local snapshot only.
14
-
15
- | Median | Previous | Current |
16
- | --- | ---: | ---: |
17
- | Largest event-loop heartbeat interval | 1288.73 ms | 18.67 ms |
18
- | Search-call duration | 1288.55 ms | 1371.55 ms |
19
-
20
- The improvement is availability for other requests, not faster CPU search. The
21
- threaded samples had modest additional elapsed time; no throughput gain is claimed.
22
- HTTP tests separately confirm ping completes while a search computation is held.
23
-
24
- The static build now pins more Reader dependencies and the app's warmup references.
25
- Immutable cache hits reuse bytes without a network request. Service Worker background
26
- writes retain event lifetime; quota failures preserve network responses; 206 responses
27
- are excluded. Installation caches the search shell and global data only.
28
-
29
- An actual Chromium install comparison served identical built resources with 25 ms
30
- request latency and empty browser contexts. The previous SW requested 47 resources
31
- (669,780 bytes); the new SW requested 16 (281,694 bytes), reducing transferred bodies
32
- by 58%. Installation took 713 ms versus 279 ms in that run. This isolates SW installation,
33
- not public-network page-render time. Old-cache upgrade, demand repository caching,
34
- immutable reuse and offline reads passed with the fixed cache name.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/reader_test_selection.py CHANGED
@@ -23,7 +23,8 @@ CATEGORY_METHODS = {
23
  "test_txt_displays_before_stream_finishes",
24
  "test_text_reader_uses_scroll_mode_without_pagination_controls",
25
  "test_reader_tab_is_hidden_for_document_without_toc",
26
- "test_txt_detects_legacy_encodings_and_multibyte_sample_boundary",
 
27
  "test_markdown_extension_aliases_render_content",
28
  "test_html_aliases_render_safely_with_visible_text",
29
  "test_malicious_html_css_and_svg_are_inert_and_keep_safe_text",
 
23
  "test_txt_displays_before_stream_finishes",
24
  "test_text_reader_uses_scroll_mode_without_pagination_controls",
25
  "test_reader_tab_is_hidden_for_document_without_toc",
26
+ "test_scanned_pdf_bookmark_has_empty_excerpt",
27
+ "test_txt_detects_legacy_encodings_and_multibyte_sample_boundary",
28
  "test_markdown_extension_aliases_render_content",
29
  "test_html_aliases_render_safely_with_visible_text",
30
  "test_malicious_html_css_and_svg_are_inert_and_keep_safe_text",
tests/test_reader_architecture.js CHANGED
@@ -12,6 +12,7 @@ for (const file of ['epub.js', 'mobi.js', 'fb2.js', 'pdf.js', 'view.js', 'progre
12
  assert.match(fs.readFileSync(path.join(root, 'static/foliate-reader/mobi.js'), 'utf8'), /createDocument/)
13
  assert.match(fs.readFileSync(path.join(root, 'static/foliate-reader/fb2.js'), 'utf8'), /resolveHref/)
14
  assert.match(fs.readFileSync(path.join(root, 'static/foliate-reader/epub.js'), 'utf8'), /String\(href \?\? ''\)/)
 
15
  const foliateReader = fs.readFileSync(path.join(root, 'static/foliate-reader/reader.js'), 'utf8')
16
  for (const message of ['voice-foliate-goto-cfi', 'voice-foliate-search', 'voice-foliate-seek', 'voice-foliate-prev', 'voice-foliate-next']) assert.ok(foliateReader.includes(message), message)
17
 
 
12
  assert.match(fs.readFileSync(path.join(root, 'static/foliate-reader/mobi.js'), 'utf8'), /createDocument/)
13
  assert.match(fs.readFileSync(path.join(root, 'static/foliate-reader/fb2.js'), 'utf8'), /resolveHref/)
14
  assert.match(fs.readFileSync(path.join(root, 'static/foliate-reader/epub.js'), 'utf8'), /String\(href \?\? ''\)/)
15
+ assert.match(fs.readFileSync(path.join(root, 'static/foliate-reader/epub.js'), 'utf8'), /item\.mediaType === MIME\.XHTML/)
16
  const foliateReader = fs.readFileSync(path.join(root, 'static/foliate-reader/reader.js'), 'utf8')
17
  for (const message of ['voice-foliate-goto-cfi', 'voice-foliate-search', 'voice-foliate-seek', 'voice-foliate-prev', 'voice-foliate-next']) assert.ok(foliateReader.includes(message), message)
18