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