Skip to content

perf(mobile): shrink the phone page by 198 KiB and lower its size fence - #44465

Merged
AmoabaKelvin merged 3 commits into
mainfrom
perf/mobile-page-bundle-trim
Nov 19, 2026
Merged

AmoabaKelvin merged 3 commits into
mainfrom
perf/mobile-page-bundle-trim

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

The phone's web page was carrying two copies of some libraries and a few pieces it never uses. This drops them, so the page is about 198 KiB smaller, and lowers the size limit by the same amount so the space doesn't fill up again.

Files Added Deleted Net
Test 0 0 0 0
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52

What Changed

Nothing users see or do changes. Only the bytes the desktop hands the phone change. Measured by verify-mobile-web-app-bundle.mjs (code bytes, without the terminal fonts and language catalogs):

bytes
main (5a6ab25) 11,017,564
this branch 10,815,616
saved ~202 KB (198 KiB)

Each cut:

  • Second build of reanimated: −140.7 KB. react-native-gesture-handler checks a reanimated class by requiring react-native-reanimated/src/.... That pulled reanimated's TypeScript source tree (185 modules) into the page next to the lib/module build the page already runs. A page-build plugin points that one require at the lib/module file. The check's answer doesn't change: neither build has _refreshComponentRef in reanimated 4.7.1, so it is false before and after.
  • react-native-web's cjs build: −9.0 KB. reanimated's web style helpers import two react-native-web StyleSheet modules from dist/cjs, beside the esm copies the page already has. They now resolve to the esm copies, which have the same default and named exports.
  • entities encode map: −23.4 KB. markdown-it only decodes HTML entities. The package root also pulls in a 23 KB new Map(...) encode table that esbuild can't drop. markdown-it's import now resolves to entities/lib/decode.js, the same file the root re-exports from.
  • buffer polyfill: −28.4 KB. Three page files used Buffer only to convert base64: file media download, dictation audio and the browser frame data URI. They now use the existing base64-byte-codec (encodeBase64Bytes / decodeBase64Bytes), which the transport already runs on both the page and Hermes. The native-only browser-frame-data-uri.ts keeps Buffer.
  • Fence: 11 MiB → 10.75 MiB. The saving stays banked, and the 446 KiB still free is close to the room build(mobile): raise the page bundle's code fence to 11 MiB #44416 gave the phone parity round.

If a later upgrade moves a redirect target, the plugin fails the build rather than quietly shipping both copies again. The entry closure (the bytes loaded before the first route) is unchanged at about 1.52 MB, so first open is no slower. One script chunk fewer.

Why

The fence has gone up four times in two days (10 → 10.25 → +216 KiB → 10.5 → 11 MiB). These are the safe cuts: duplicate builds and code nothing calls. They change no screen, no text and no RPC.

The bigger items are listed below. Each one needs a product call or carries real risk, so this PR leaves them alone:

  • mermaid engine: 3.2 MB, 29% of the fence. It is already one lazy chunk. Real cuts would mean dropping diagram types. Building it for the page's real floor (Chrome 101 / iOS 16) instead of chrome74/safari15 would save about 44 KB, but Metro and Hermes compile that generated file too, so it needs a native check first.
  • KaTeX fonts (~300 KB), the xterm webgl addon (253 KB) and the 36 highlight.js languages (169 KB). These are features.

Linked Issue

N/A (fleet task from Kelvin: shrink the phone page bundle)

Visual Proof

N/A: the page renders the same. Only duplicate modules and an unused encode table leave the bundle, and the base64 calls produce the same strings and bytes.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • pnpm build:mobile-web (build + verify, reproducible buildId) on main and on this branch. Numbers above.

  • A metafile breakdown confirmed react-native-reanimated/src/**, react-native-web/dist/cjs/**, entities/.../encode-html.js and buffer are no longer in any output.

  • Mobile vitest: bridge-audio-verbs, mobile-dictation-session-outcomes and src/test-support/rpc-recording (122 tests) pass.

  • build-mobile-web-app-bundle.test.mjs (shim list) and pnpm check:changed pass.

  • No new tests: each cut is a build-resolution or call-site swap, and the verify fence already guards the size.

Risk

Level: Low

The riskiest part is the reanimated redirect, because gestures and animations run through reanimated on every page. Only the gesture-handler probe's require moves. require('react-native-reanimated') already loads the same lib/module tree at that point, so evaluation order doesn't change.

The base64 swap is stricter on malformed input (atob throws where Buffer skipped bad characters). Hosts send Node Buffer.toString('base64') output, so that can't happen on a real path.

The lower fence means a phone PR that adds more than about 446 KiB fails build:mobile-web on size and has to cut bytes or ask.

Back out with a plain revert.

Review

One review round (Codex + Claude). Codex found nothing. Claude rated a first 10.5 MiB fence P2 because it would squeeze the phone parity branches still in flight, so the fence is now 10.75 MiB.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Older phone shells and hosts are unaffected. The manifest format is unchanged, and the page is only smaller.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@AmoabaKelvin
AmoabaKelvin force-pushed the perf/mobile-page-bundle-trim branch from be64452 to 3304b86 Compare November 19, 2026 17:12
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The mobile web build adds a plugin that redirects configured package imports and registers it with esbuild. The documented bundle-size ceiling changes from 11 MiB to 10.75 MiB. Mobile browser, file-download, and audio code now use the transport byte codec for base64 operations, and the dictation session state module no longer exports its base64 helper.

Merge Risk: Minimal · up to 3304b

This change shrinks the mobile web bundle by removing duplicate library builds and the Buffer polyfill, and it lowers the size fence. No concrete defect was found. The redirects fail the build if a target moves, and the base64 call sites keep their existing behavior for real inputs. It appears safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: shrinking the mobile phone web page bundle by about 198 KiB and lowering its size fence. The changeset removes duplicate reanimated and react-native-web builds, the en…
Description check Passed The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Risk, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist sections. It …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: shrinking the mobile phone web page bundle by about 198 KiB and lowering its size fence. The changeset removes duplicate reanimated and react-native-web builds, the entities encode map, and the Buffer polyfill, and it lowers MOBILE_WEB_APP_BUNDLE_MAX_TOTAL_BYTES from 11 MiB to 10.75 MiB. The title is specific and follows a conventional commit style.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Risk, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist sections. It explains the before and after, the mechanism of each cut, the alternatives it rejected, and the back-out path. Two gaps remain. The Linked Issue section cites a fleet task, not an issue, and the template asks for an actual issue link. The Risk level is given as Low, and the AI Disclosure section is blank, which the template allows only for internal team members.

Resolution

Optionally link a real issue in the Linked Issue section, or confirm that the internal-contributor exemption applies. Also confirm whether the AI Disclosure section can stay empty.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c74374e1-54dc-43af-9b90-eb893af7764e
Commits

Reviewing files that changed from the base of the PR and between f0ba83a and 3304b86.

Files selected for processing: 8

  • config/scripts/build/mobile-web-app/build-mobile-web-app-bundle.mjs
  • config/scripts/build/mobile-web-app/one-package-build-plugin.mjs
  • config/scripts/build/mobile-web-app/verify-mobile-web-app-bundle.mjs
  • mobile/src/browser/screencast/browser-frame-data-uri.web.ts
  • mobile/src/files/media/mobile-file-media-download.ts
  • mobile/src/hooks/mobile-dictation-audio-chunk.ts
  • mobile/src/hooks/mobile-dictation-session-state.ts
  • mobile/src/platform/audio-capture/native-audio.ts
Files with no reviewable changes: 1

  • mobile/src/hooks/mobile-dictation-session-state.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@AmoabaKelvin
AmoabaKelvin merged commit 43bfdd3 into main Nov 19, 2026
43 checks passed
Fartown pushed a commit to Fartown/orca that referenced this pull request Nov 21, 2026
上游 stablyai#44465 收紧预算后纯上游仅余约 205 KB,fork 路由实测约 355 KB。上游常量保持 10.75 MiB,fork 额度 360 KiB 单列、只降不升(journal D-030);顺带登记终端粘贴测试接缝。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GvYgJTtZiP6G3CVdLZKC6C
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