Repository navigation
⚡️ 优化资源下载分块性能 - #1753
Merged
Merged
⚡️ 优化资源下载分块性能#1753
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist / 检查清单
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.
本次改动
实现考虑
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.