Skip to content

⚡️ 优化资源下载分块性能 - #1753

Merged
CodFrm merged 1 commit into
scriptscat:mainfrom
cyfung1031:codex/perf-resource-chunk
Sep 20, 2026
Merged

CodFrm merged 1 commit into
scriptscat:mainfrom
cyfung1031:codex/perf-resource-chunk

Conversation

@cyfung1031

Copy link
Copy Markdown
Collaborator

Checklist / 检查清单

  • Fixes mentioned issues / 修复已提及的问题
  • Code reviewed by human / 代码通过人工检查
  • Changes tested / 已完成测试

N/A — no issue was linked to this performance change.

Description / 描述

背景

The chunk handler added by 5cb899a rebuilt a Blob from the entire Base64 resource for every 16 MiB request, then sliced it. A three-chunk download therefore decoded the same 48 MiB resource three times. Resource-list byte sizes also decoded each complete Base64 payload just to count its bytes.

本次改动

  • Calculate Base64 byte size from encoded length and padding.
  • Decode only the Base64 groups covering the requested byte range. The response shape and exact bytes are unchanged; text-only resources keep the existing Blob path.

实现考虑

The range decoder aligns to Base64's three-byte groups, then trims the leading and trailing boundary bytes before re-encoding the requested range. This keeps the existing chunk contract without materializing a full-resource binary string, byte array, or Blob for each request.

A local Node microbenchmark used Node v25.9.0 on Darwin 23.6.0 arm64 and a deterministic 48 MiB fixture split into three 16 MiB requests. Across three full-download runs, median time was 439.5 ms for full-resource decode per chunk and 59.6 ms for range decode; decoded source volume fell from 144 MiB to 48 MiB. Each returned chunk was checked byte-for-byte. The same 48 MiB byte-size lookup took a median 27.6 ms with full decoding and 0.023 microseconds with length/padding arithmetic. These are Node-level measurements, not an end-to-end browser extension benchmark.

建议审查重点

Check Base64 offsets that are not divisible by three and the padded final range; the service test covers both.

验证

  • pnpm exec vitest run --no-coverage --reporter=dot src/app/service/service_worker/resource.test.ts 'src/pages/options/routes/ScriptEditor/tabs/ResourcePane.test.tsx' — 2 files, 52 tests passed.
  • pnpm run lint — passed.
  • pnpm run build — passed; Rspack emitted asset-size and Monaco dynamic-dependency warnings.

Screenshots / 截图

N/A — no UI change.

@CodFrm
CodFrm merged commit 317fbc5 into scriptscat:main Sep 20, 2026
10 checks passed
@cyfung1031
cyfung1031 deleted the codex/perf-resource-chunk branch October 10, 2026 23:32
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