Skip to content

perf: Store prompt media on disk and reduce memory usage - #290

Merged
Mag1cFall merged 2 commits into
Mag1cFall:mainfrom
paralax034:perf/playground-media-memory
Nov 22, 2026
Merged

Mag1cFall merged 2 commits into
Mag1cFall:mainfrom
paralax034:perf/playground-media-memory

Conversation

@paralax034

Copy link
Copy Markdown
Contributor

Changes

  • Stream prompt media attachments by SHA-256 content hash into runtime/prompt-media/ via POST /api/prompts/media, serve them with HTTP Range support on GET /api/prompts/media/{id}, and track media references and orphan reclamation in prompts.db (media and prompt_media tables)
  • Store mediaId references for uploaded and generated Playground attachments, load previews, PDF thumbnails, and text excerpts directly from the media endpoint, hydrate non-Drive attachment payloads on demand for requests and token counts, and renew expired Drive video uploads sequentially; temporary chats keep local Blob references and persist them to the media store on save or branch
  • Coalesce queued prompt saves, release temporary Object URLs and in-flight token count requests on chat switch, delete, rerun, or compare pane close, and revoke Object URLs when VideoResult downloads are aborted
  • Preallocate Go request body buffers up to a bounded cap from ContentLength, release raw Base64 strings after decoding inlineData, bound concurrent inline Drive uploads, and clear the mp4Duration moov buffer once parsed

Verification

  • go vet ./...
  • go test -mod=readonly ./cmd/... ./internal/...
  • cd web && npm run typecheck && npm run lint && npm run format:check && npm run build
  • Measured on a chat with 6 uploaded videos (333 MB total) in Zen / Firefox (about:memory) and Windows Task Manager: frontend memory delta dropped from +1.31 GB to +72 MB, and aistudio2api.exe working set dropped from 2.16 GB to ~203 MB

paralax034 and others added 2 commits November 22, 2026 12:20
- 修复媒体去重表待保存保护、MIME 参数保留、句柄占用磁盘回收与 JSON 转义引用解析
- 保留媒体响应的 no-store 缓存头并按时间间隔回收运行期未关联孤儿媒体
- 拆分附件媒体存储模块消除循环依赖,落盘优先读服务端副本并统一上传生成与分支内联媒体
- 修复切换对话与取消读取时的运行态、token 统计、OpenAI 图片历史读取及队列删除竞态
@Mag1cFall
Mag1cFall merged commit d0008f5 into Mag1cFall:main Nov 22, 2026
4 checks passed
@Mag1cFall

Copy link
Copy Markdown
Owner

Thanks for contributing!

Mag1cFall added a commit that referenced this pull request Nov 25, 2026
perf: Store prompt media on disk and reduce memory usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants