Skip to content

SWF(perf): Slim the web client bundle - #1843

Closed
Fei2411 wants to merge 11 commits into
devfrom
fix/1019-slim-web-bundle
Closed

Fei2411 wants to merge 11 commits into
devfrom
fix/1019-slim-web-bundle

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Issue

Refs #1019

The esbuild step now strips whitespace and minifies syntax in client.js, which cuts the startup bundle by 14% raw and 3% gzip. Only the build changes; the UI is untouched.

What changed / 改了什么

  • ds-bot/scripts/build-client.mjs: minifySyntax and minifyWhitespace (with lineLimit: 180), but no identifier renaming.
    • The leak scan recognizes the existing storage-migration lines by their LEGACY_* names, so those names must survive the build.
    • keepNames stays off. It would inject a bundle-scoped __name helper into readPage, which is serialized and run inside the Bot browser page.
    • Tree shaking stays off and charset: 'utf8' is kept. The scanner and the migration source are unchanged. client.js is regenerated.
  • ds-bot/test/client-bundle.test.js adds three tests:
    • A 2.5 MiB startup budget. It fails on dev.
    • The shipped page reader, taken from the built client.js, runs with no bundle scope.
    • The shipped client still migrates both legacy preference prefixes and both v1 browser-tab keys.
  • ds-bot/test/reading.test.js and ds-bot/test/user-bubble.test.js: they now read CSS and wiring from source, or allow for line continuations, instead of relying on generated formatting. The assertions are unchanged.

Trade-off: the shipped client.js is denser to read in devtools. Names are kept and lines are capped at 180 characters. The source of truth is src/client/.

Measurements

Metric dev This PR
DS Bot client.js, raw / gzip (current head 333873e vs current dev) 2,929,921 / 773,335 B 2,528,962 / 749,214 B
All startup JS served (DSH + DS Bot), raw / gzip 14,393,309 / 4,029,757 B 14,009,652 / 3,982,938 B
Throttled Chromium, iPhone 13: window load / ready UI 11.029 / 11.346 s 10.940 / 11.297 s
DS Bot bundle: background parse elapsed / main-thread compile + evaluate 6.665 s / 1.618 ms 6.478 s / 1.383 ms
Unthrottled WebKit, iPhone 13: window load / ready UI 1.557 / 1.686 s 1.557 / 1.693 s

How it was measured. The first row is from the current head and current dev. The other rows were measured at c8d384fe against the dev of that time; since then only other PRs' source has been merged in. Each timing is the median of 7 interleaved cold runs per build and engine. Every run used a fresh Playwright iPhone 13 context on macOS against the same pinned DSH 0.2.2-rc.1 mock bench.

  • Chromium 154: CPU slowed 4×; network at 100 ms latency and 4/1 Mbps down/up.
  • WebKit: no throttling hooks, so it ran unthrottled as a sanity check. Its difference is noise.
  • Ready UI: the loading placeholder is gone and the composer is rendered.
  • Sizes: HTTP response bodies. DSH serves gzip but not Brotli.

What this does not fix. About 11.5 MB raw of the 14.4 MB startup JavaScript is DSH's own client. DS Bot can't change that without patching DSH (hard rule 1), so a real cut needs a DSH-side change. DS Bot's own bundle already costs under 2 ms on the main thread, so the gain here is transfer and parse only. #1019 should stay open.

Changelog

The web client downloads slightly less JavaScript at startup.

How I checked it / 怎么验证的

  • npm test (in ds-bot/) on the current head: 3421 tests, 3417 pass, 0 fail, 4 skipped
  • node scripts/build-client.mjs --check: exit 0
  • npm run lint: exit 0
  • Leak scan locally: must fix: 0; CI Leak scan passes
  • Smoke run in WebKit (iPhone 13) on the first head: sent a message and the mock answer rendered, with no page errors. Before (left, dev) and after (right) are identical apart from mock timestamps:

chat before/after

Try it: cd ds-bot && npm ci && node scripts/build-client.mjs --check && node --test test/client-bundle.test.js

Untested:

Other PRs: #1829 and #1841 have both landed. This branch has been merged with dev after them, and client.js was rebuilt each time, as it was after #1776, #1150 and #1594. No open PR is waiting to land before this one.

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 改了 src/client/ 就已重新 build 并提交 client.js。
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息,截图里也没有。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。

Software Factory opened this PR for Lulu
Implemented in session Slim web client bundle for mobile Safari
Review with Devin · Open in Devin Desktop


Reduce cold-start JavaScript without changing DSH module registration or the client UI. Keep function and class names for readable diagnostics.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T09:30:53.591690Z 2fe2687 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fe2687a91

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ds-bot/scripts/build-client.mjs Outdated
treeShaking: false,
// Readable for debugging in the browser: no minification, and Chinese text stays text.
minify: true,
keepNames: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the serialized page reader free of bundler helpers

In the desktop app and DSH Desktop, read_browser now fails for every open page. With keepNames: true, esbuild inserts calls to its outer name-preservation helper inside readPage (for example, n(..., "collapse")). However, src/client/read-page.js serializes that function into READ_PAGE_SCRIPT, which bot-browsers.js executes in the isolated page through executeJavaScript; the helper is not present there. Evaluating the reader extracted from this commit's bundle reproduces ReferenceError: n is not defined. Build the serialized reader without name-preservation helpers, or otherwise keep it self-contained, and test the reader using the actual production build options.

Useful? React with 👍 / 👎.

Esbuild's keepNames transform adds a helper from the bundle scope to serialized page-reader code. Remove the transform and exercise the shipped function source in an isolated realm.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: not ready for lulu. The required Leak scan fails on this head; I reproduced it locally while the same scan passed on dev. Minification renames LEGACY_PREFIXES and LEGACY_BROWSER_KEYS, so the scanner no longer recognizes three existing browser-storage migration literals in generated client.js. Keep the migration intact and make the scanner/build recognize only those known migration occurrences, without exempting the bundle or weakening the other checks. Rebuild and rerun the scan.

The fresh bundle check, isolated page-reader test, and full unit suite passed locally. Please update the PR description: this head drops keepNames; I measured 2,160,662 B raw and 663,540 B gzip. Keep #1019 open: this is a size reduction, not a verified fix for the reported physical-iPhone Safari load failure.

Merge order: land #1829 first once it is independently ready. Its merge with this PR is textually clean but produces a stale client.js; rebuilding the combined tree restored both build checks and all 28 focused tests passed. Run scripts/merge-dev.sh on whichever branch lands second. I found 35 otherwise-mergeable open PRs sharing only the generated bundle with this PR; 28 would conflict in that file, including #1841. Ready client fixes can land while this PR is blocked; rebuild from the latest dev after they land.

Written by Devin

Preserve source identifiers and keep generated lines short so the existing leak scan recognizes the storage migration. Verify migration from the shipped client for both old prefixes and browser storage versions.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated bundle is about 13% smaller uncompressed (about 3% with gzip), and the 2.5 MiB budget passes. The shipped reader runs outside bundle scope in the regression test, addressing the earlier helper concern; the preference migration and reading tests also passed. I found no overlapping open bundle-minification change.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 finding. Devin automatically fixed it.

Fixed by Devin (1)
  • Desktop browser page reading fails — Dropped keepNames so no bundle-scoped __name helper is injected; new test runs the shipped reader in isolation.

View findings in Devin Review · Follow Devin's work

Devin Review

@Fei2411

Fei2411 commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

经评估暂不合入,先关闭。

@Fei2411 Fei2411 closed this Nov 20, 2026
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.

1 participant