Skip to content

[Bug]: iOS app draws ~2.8x the power of a minimal Flutter client while a turn streams #27325

Closed

Description

@dbxe

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/mobile

Steps to reproduce

  1. On an iPad, open a thread in the T3 Code app and let an agent turn stream into it.
  2. Measure whole-device power from the battery gauge (PowerTelemetryData.AccumulatedSystemLoad via pymobiledevice3, battery held at its charge limit so it neither charges nor discharges).
  3. Repeat with a minimal Flutter client against the same server, the same thread and the same replayed turn (dev Replay provider), alternating the two apps in ABBA blocks.

Expected behavior

Watching a turn stream costs about what it costs in a minimal Flutter client, since the screen content is the same.

Actual behavior

Idle screens cost the same, but streaming costs about 125 mW more, so the app's own cost while streaming is ~2.8x the Flutter client's. In daily use the battery percentage visibly drops minute by minute while a turn runs.

Phase (2 min each, 2 ABBA blocks) T3 Code Flutter client Difference per block
Thread list, idle ~980 mW ~980 mW −6 / +6
Long thread open, idle ~981 mW ~967 mW −16 / −14
Turn streaming ~1135 mW ~1010 mW −126 / −123
App in background ~941 mW ~945 mW +11 / −5

Device floor (Settings app in front) is ~940 mW, so above the floor streaming costs ~195 mW in T3 Code and ~70 mW in the Flutter client. The bench resolves about 25 mW; the same build against itself moves at most 8 mW per block.

Where it goes, largest first:

  1. Work-row shimmer: measured 55-72 mW. A build without it saved that much while streaming. The native-driver loop steps and clones props on the main thread every frame, and the compositor redraws behind the glass surfaces. A Core Animation version with identical visuals recovers only ~20 mW, so most of the cost is the animation itself.
  2. The whole growing message is re-parsed and re-laid out on every update (apps/mobile/src/native/EnrichedMarkdownText.tsx), about 2.5 times a second over an ever-longer string. The Flutter client keeps finished blocks and reparses only the open tail. Not yet measured on its own.
  3. Thread-wide state publication per update (packages/client-runtime/src/state/threads.ts): each update republishes the thread projection and wakes route and composer subscribers. The JS thread spends ~2.8 s of CPU per minute while streaming, ~77% of it in Promise jobs. Not yet measured on its own.
  4. Liquid Glass composer and Working pill over the moving feed: the render server spends ~8 s more CPU per minute while streaming than at idle. Not yet measured on its own.

Separately, on an idle screen three display links tick every frame: worklets' requestAnimationFrame loop re-requests itself forever, Reanimated's 500 ms props flush keeps React Native's timer display link running, and expo-app-metrics' frame recorders (via expo-observe) run for the app's lifetime. Removing them shows clearly in Instruments, but it stays below 25 mW on this bench.

Related: #24796 (Android battery report, cause unknown) and #9661 (performance audit tracker).

I'd like to fix this with focused, measured PRs, starting with the ones that change nothing visible (2 and 3, then the idle loops). The shimmer's cadence is a product call, so I'd raise it as an Ideas discussion.

Impact

Major degradation or frequent failure

Version or commit

main @ dac8b11 (mobile Release build, personal-team signed, OTA off)

Environment

iPad mini (A17 Pro), iPadOS 26.7.2, Wi-Fi, minimum brightness, server over Tailscale

Method

Same iPad, same isolated server seeded from real data, restored from a snapshot before each trial. The app is driven only by deep links and server CLI calls, never touched during a measured window. Each phase settles 30-40 s, then measures 120 s. Blocks alternate ABBA/BAAB with a floor run between blocks. A run is rejected if the battery charges, discharges or changes temperature. Screenshots after every phase confirm both apps show the same content. Profiles: Instruments Time Profiler, attached and all-process, on Release builds.

Activity

  1. dbxe commented on Oct 30, 2026

    @dbxe
    Author

    Note

    🤖 Claude Opus 5.5 responding on behalf of Daniel Briskin

    I measured the issue's other suspects tonight. Only the shimmer clears the bench, so items 2-4 in the issue are smaller than the issue suggests.

    Each row is a 2-block streaming trial, in mW per block. The bench resolves about 25 mW.

    Candidate (against dac8b11ddc unless noted) Result
    Work-row shimmer removed −66 / −61 (earlier −55 / −72)
    Markdown: finished blocks memoised, only the open tail re-parsed (item 2) +3 / −12
    Route, composer and shell subscriptions narrowed so a text tick only re-renders its row (item 3) −8 / +8
    #27425's selectors −5 / −11
    Liquid Glass off (item 4, diagnostic) −16 / −1
    Stream haptics off (diagnostic) +5 / −19
    All the invisible candidates together, all phases streaming +8 / −17 (no phase moved)
    Streamed text growth dropped on the client (diagnostic: a message shows its first chunk, then its final text) 0 / +1
    The same, with the shimmer also removed −59 / −70
    Reduced motion forced and the 1 Hz duration labels stopped, measured against shimmer removed −13 / −22
    1 Hz duration labels stopped only −23 / −16
    Reanimated layout/entering animations off only +1 / +27 (one outlier run)
    All the invisible candidates together, 4 blocks, streaming −28 / −6 / +1 / −27

    So on this bench, rendering the growing text costs nothing measurable. Without the shimmer, a streaming screen still costs ~100 mW more than an idle open thread. Text, glass, haptics and motion don't explain it.

    Network traffic is the next lead. I counted the Tailscale extension's bytes on the server host over the same 120 s streaming window, alternating the two clients twice. "Into the tunnel" is the server's outgoing data before encryption; "on the wire" is the encrypted packets, including overhead.

    Client Into the tunnel On the wire Power
    T3 Code 582 / 575 KB 656 / 651 KB 1078 / 1069 mW
    Flutter client 72 / 74 KB 114 / 120 KB 935 / 940 mW

    That's ~8x the payload for the same turn. (An earlier edit of this comment called the first column upstream; that was my misreading of the counters.)

    Likely cause of the downstream gap (from the code; not yet confirmed on the wire):

    • The server enables permessage-deflate with context takeover (apps/server/src/server.ts).
    • message.updated resends the whole growing message on every tick, which compresses very well under that setting.
    • Dart's WebSocket.connect negotiates deflate by default. React Native's iOS WebSocket (RCTWebSocketModule on SocketRocket) doesn't support it, so the app likely receives every tick uncompressed.

    A Node client on the bench server, subscribing to the same replay thread with the app's own options, received 343 KB uncompressed vs 19 KB with deflate (18x) in the same 120 s window. Both got identical payloads. That fits the app's ~580 KB (thread plus shell streams), #24931 (a URLSession WebSocket on iOS) fixes the byte gap on the device: 122 KB vs 755 KB. But power read −25 / +7 mW in portrait (−6 / +1 in an earlier landscape run), unchanged, so on Wi-Fi the bytes aren't what costs power. Cellular is untested, and it's where they should matter most. The Flutter client subscribes to no less than the app does: both get the same thread and shell streams, and the app even asks for deduplicated bodies.

    One caveat on item 2: this bench's assistant messages are short, about 250 words between tool calls, so it doesn't exercise one very long message.

    The shimmer needs a visible change to pay off fully, so I opened #27684 for the direction. I won't open PRs for the candidates that read within noise.

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