Skip to content

Mobile: Cut the per-update native commit cost of the streaming draft bubble #1838

Closed

Description

@DoodleBears

Problem and context / 问题与背景

After #1811 (closes #1803), a streamed reply no longer re-renders the rest of the DM:

  • MessageBubble renders 0 times per draft update.
  • About 71 components render per commit, against 894–1,535 before.
  • Closed Markdown blocks are reused.

Each draft update still costs about 120 ms of JS on the dev build (iPhone 16 Pro Simulator, iOS 18.6, one 1,682-word reply replayed at 4 characters every 16 ms). The time goes to:

  • Fabric completeRoot / replaceContainerChildren: 34% of JS time.
  • React DEV createTask: 20%, which a release build does not have.
  • GC: 5%.

As a result:

  • The screen draws about 4 draft updates a second, while the 50 ms batching would allow 20.
  • JS FPS during a stream is 34–43.
  • A stream has 226–237 frames over 50 ms.
  • UI-thread FPS, native dropped frames and release-build numbers have not been measured.

Measured with apps/mobile/scripts/rn-profile.mjs; the full numbers are in the #1811 description. (Also filed as #1839, closed as a duplicate of this.)

Smallest useful scope / 最小有用范围

Included:

  • Measure the release build first, and the UI thread through xctrace (Time Profiler / Animation Hitches) or the Performance Monitor. Find where the per-update native commit cost goes.
  • Add UI-thread frame timing to the profiling loop in apps/mobile/AGENTS.md if it can be read from the command line.
  • Reduce the cost with the cheapest change the profile points to, for example:
    • keep only the growing tail block as the node that changes, and slim its native view tree;
    • split the tail block;
    • avoid re-laying out the list cell on each update;
    • adapt the batching interval to the measured commit time.

Excluded:

How to verify / 如何验收

  • Profile the same replayed reply on main and on the change, at least three runs each in ABBA order, as apps/mobile/AGENTS.md (Profiling) describes.
  • The PR records:
    • JS time per draft update;
    • draft updates drawn per second;
    • JS FPS;
    • UI-thread FPS or hitches, if measurable.
  • Done when, in a release build, each draft update costs well under one frame of JS and the reference stream has no frames over 50 ms.
  • No regression in MessageBubble renders per draft update (stays 0), and the Vitest suite stays green.

Activity

  1. DoodleBears commented on Oct 14, 2026

    @DoodleBears
    ContributorAuthor

    Agent work claim

    • Agent: Claude Code
    • Task: claude-code/local/03081932-a680-44a7-bb8e-76677b7b0c7b (not a DSH Session)
    • Issue scope: render chat Markdown with react-native-enriched-markdown (native text), DraftBubble first then MarkdownView everywhere; streaming drafts closed with remend; ABBA profile against main incl. release build if possible
    • Branch: claude/1838-enriched-markdown
    • Started: 2026-10-14 21:46 UTC
    • State: active
  2. added
    agent:activeOne or more coding-agent tasks currently claim this issue; see claim comments for task IDs
    on Oct 14, 2026
  3. DoodleBears commented on Oct 15, 2026

    @DoodleBears
    ContributorAuthor

    Agent work outcome

    • Task: claude-code/local/03081932-a680-44a7-bb8e-76677b7b0c7b
    • State: completed
    • PR: Render mobile chat Markdown as native text (react-native-enriched-markdown) #1840 (merged as 9c39346)
    • Remaining scope: in production JS each stream still has 3–4 frames of ~100 ms (the issue's "no frames over 50 ms" is not fully met); a store Release build and UI-thread frames were not measured; on iOS the nested-list bullet sits against its text and links render in the ink colour instead of the accent.
  4. removed
    agent:activeOne or more coding-agent tasks currently claim this issue; see claim comments for task IDs
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions