perf: lazy-load file content + fix oversized tile labels #5

Merged
fam merged 3 commits from perf/lazy-load-and-font-fix into master 2026-04-07 09:38:49 +00:00
Owner

Fixes #2

问题

  1. 大 repo(如 claude code)全局视图很慢——服务端一次性把所有文件内容打包进初始 JSON,几十 MB 下载 + computeColorRanges 对每个文件同步跑 highlight.js,直接卡住
  2. 大 tile 上的标签字体太大(min(w,h) * 0.15 无上限,容易算出 20–30 world units)

改动

服务端 (server/src/main.rs)

  • 初始响应改为 metadata only(不含 content),新增 strip_content() 在发送前递归清空
  • 响应格式从 FileNode 改为 TreeResponse { cache_key, tree },前端拿到 key 后可按需拉内容
  • 新增 GET /api/repos/{key}/file?path=... 按单文件返回内容(从 SQLite cache 中读全树再定位)
  • Cache 本身仍存完整内容,不影响重复访问

前端 (web/src/renderer.js, web/src/app.js)

  • load() 不再调用 computeColorRanges,彻底去掉加载时的同步 CPU 突刺
  • _showCode() 发现 tile.data.content 为空时,调用 _fetchContent() 异步拉取,拿到内容后再计算 colorRanges
  • loading 标志防止重复 fetch
  • 标签字号加 cap:Math.min(Math.min(w, h) * 0.15, 5)
Fixes #2 ## 问题 1. 大 repo(如 claude code)全局视图很慢——服务端一次性把所有文件内容打包进初始 JSON,几十 MB 下载 + `computeColorRanges` 对每个文件同步跑 highlight.js,直接卡住 2. 大 tile 上的标签字体太大(`min(w,h) * 0.15` 无上限,容易算出 20–30 world units) ## 改动 ### 服务端 (`server/src/main.rs`) - 初始响应改为 **metadata only**(不含 `content`),新增 `strip_content()` 在发送前递归清空 - 响应格式从 `FileNode` 改为 `TreeResponse { cache_key, tree }`,前端拿到 key 后可按需拉内容 - 新增 `GET /api/repos/{key}/file?path=...` 按单文件返回内容(从 SQLite cache 中读全树再定位) - Cache 本身仍存完整内容,不影响重复访问 ### 前端 (`web/src/renderer.js`, `web/src/app.js`) - `load()` 不再调用 `computeColorRanges`,彻底去掉加载时的同步 CPU 突刺 - `_showCode()` 发现 `tile.data.content` 为空时,调用 `_fetchContent()` 异步拉取,拿到内容后再计算 colorRanges - `loading` 标志防止重复 fetch - 标签字号加 cap:`Math.min(Math.min(w, h) * 0.15, 5)`
ms added 3 commits 2026-04-07 09:38:11 +00:00
- Server now returns metadata-only tree on initial load (no file content
  in the JSON payload); content is served on-demand via the new
  GET /api/repos/{key}/file?path=... endpoint
- Cache still stores full content; strip_content() runs in-memory before
  the response is sent
- Frontend fetches file content lazily in _fetchContent() when a tile
  enters the LOD view, preventing a massive upfront JSON download for
  large repos (e.g. claude code)
- computeColorRanges() is now deferred to first _showCode() call instead
  of running synchronously for every file during load()
- Cap label fontSize at 5 world units to prevent giant text on large tiles
fam merged commit b3652f2cb0 into master 2026-04-07 09:38:49 +00:00
fam deleted branch perf/lazy-load-and-font-fix 2026-04-07 09:38:49 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: euphon/repo-vis#5