Wednesday, September 30, 2026 Newsletter Advertise
Breaking
AI

Instagram Direct cuts AI agent token cost 33% with Jetpack Compose

Meta and Google say rebuilding Instagram Direct's Android UI around Compose halved the UI code and made AI coding agents cheaper and faster on the codebase.

Instagram Direct cuts AI agent token cost 33% with Jetpack Compose. Source: Google

Engineers from Meta and Google said on September 30, 2026 that rebuilding Instagram Direct's Android interface with Jetpack Compose produced a UI codebase 50% smaller than the original and cut the token cost of AI agent sessions by 33%. The account was published on Google's Android Developers Blog by Pavlo Stavytskyi of Meta and Rebecca Franks of Google, written in collaboration with the Meta team.

What Meta and Google say changed

According to the post, Instagram Direct handles billions of user messages every day and had been heavily optimized on the legacy Android View system. The teams said maintaining that surface created technical debt and engineering overhead as teams adopt declarative UI and AI coding assistants.

Rather than pointing AI tools at existing code, the Instagram Direct team said it redesigned the codebase and architecture to be "AI-native by design," choosing Jetpack Compose because its declarative nature makes code more concise and structurally easier for AI models to reason about.

The post describes the scale involved: individual UI components can render in over 160 distinct state permutations, and a single conversation screen handles more than 200 distinct message types.

The reported numbers

Meta said an internal data analysis of the Instagram Direct Android codebase compared AI agent sessions working on Compose UI against the same tasks using Android Views. Per character of landed code, the company reported 32% fewer engineer-agent exchanges and 35% less agent execution time; per agent session, total token cost dropped 33%.

The post also cites a Meta risk score that evaluates code quality and the likelihood of a change causing production incidents. When a file's accumulated risk score doubles, the teams said View-based UI reduces agent resource efficiency by 30% per landed character, while the reduction for Compose UI is only 9%.

These are internal measurements disclosed by Meta and Google; the post does not describe independent verification.

Architecture and migration approach

The post warns that mixing declarative and imperative UI code invites AI tools to blend them incorrectly, introducing subtle bugs, tech debt and performance regressions. It sets out two rules for an AI-friendly codebase: minimize dependency on custom context, and let the architecture itself enforce boundaries rather than patching gaps with AI skills that cost tokens.

Several hundred list items were migrated gradually inside the existing RecyclerView architecture and rolled out in small independent groups under A/B tests, the teams said, before the team moved to replace the RecyclerView core with the Compose-native LazyColumn. An interop API let the same Compose items run in either setup, switchable at runtime via feature flags.

New Compose capabilities

The partnership produced additions to Jetpack Compose, according to the post. Pausable composition, enabled by default in Compose 1.10, composes expensive lazy-list items incrementally across frames to prevent jank. LazyLayoutCacheWindow, added in Compose 1.9, keeps off-screen items composed around the viewport.

In recent internal testing at Meta, combining pausable composition with a one-viewport cache window reduced large frame drops per minute by about 13% compared with vanilla Compose, while the cache window alone reduced it by about 8%, the post said.

The onVisibilityChanged API, added in Compose 1.9.0, gives large Compose surfaces a consistent way to know when a composable is visible; Instagram Direct uses those signals across hundreds of files. Startup performance inside Direct was optimized with Baseline Profiles, the teams said.

What to do

  • Google says developers can use Compose 1.13.0-alpha03 to try LazyLayoutCacheWindow, configuring it either with fixed Dp values (for example ahead = 150.dp, behind = 100.dp) or viewport fractions (for example aheadFraction = 0.5f, behindFraction = 0.3f), then passing it to LazyColumn.
  • The post advises pairing pausable composition with LazyLayoutCacheWindow, saying the combination yields better results than cache windows alone because a heavy item could otherwise compose in a single pass and overrun the frame budget.
  • Because ideal cache window values depend on content structure and item sizes, the teams say finding the right balance requires experimentation.
  • When migrating, the post recommends moving bigger surfaces rather than individual small components, to keep the UI in a single uninterrupted composition hierarchy and avoid interop bridging costs.
  • Google and Meta suggest using Baseline Profiles to pre-compile hot code paths at install time so Compose renders quickly from first launch, and encourage developers to send feedback and contributions to the open-source Compose toolkit.
Key facts and where they come from
  • Meta says the rebuilt Instagram Direct UI codebase is 50% smaller than the original.
    the team built an AI-native UI codebase that is 50% smaller than the original implementation
  • Reported AI agent gains: 35% less execution time, 32% fewer exchanges, 33% lower token cost.
    a 35% reduction in AI agent execution time, 32% fewer engineer-agent exchanges, and a 33% reduction in token cost
  • A single Instagram Direct conversation screen handles more than 200 distinct message types.
    a single conversation screen alone handles more than 200 distinct message types
  • When a file's risk score doubles, Views cut agent efficiency 30%, Compose only 9%.
    the UI implemented with Android Views reduces agent resource efficiency by 30% (per landed character). In the same circumstances, the reduction by Jetpack Compose UI is only 9%
  • Pausable composition is enabled by default in Compose 1.10.
    Pausable composition (enabled by default in Compose 1.10) allows expensive lazy-list items to be composed incrementally across frames to prevent jank.
  • Meta measured about a 13% cut in large frame drops per minute combining both features.
    combining Pausable composition with a one-viewport LazyLayoutCacheWindow reduced large frame drops per minute (LFDs/m) by about 13% compared with vanilla Compose
  • onVisibilityChanged was added in Compose 1.9.0 and is used across hundreds of files in Direct.
    The onVisibilityChanged (added in Compose 1.9.0) API was another key result of the technical partnership between Google and Meta.

Read the original from Google →

The TechUpscale Brief

The day's cyber, AI and tech news in one short email, every weekday morning. Free. Unsubscribe anytime.

I'm most interested in

More AI