In a collaborative technical achievement bridging two of Silicon Valley’s tech giants, engineers from Meta and Google have detailed how a massive architectural overhaul of Instagram Direct transformed the messaging platform into an AI-native codebase. By moving away from the legacy Android View system and fully embracing Jetpack Compose, the Instagram team managed to shrink the core UI codebase by half while drastically improving performance and streamlining AI-assisted engineering workflows.

Instagram Direct handles billions of user messages every single day, making it one of the most heavily trafficked and critical surfaces within the broader Instagram application. Over years of steady feature iteration and minor updates, the engineering team had squeezed every possible micro-optimization out of the legacy Android View architecture. However, maintaining and expanding a heavily customized legacy environment carries substantial technical debt and high engineering overhead. This burden became increasingly apparent as Meta teams began adopting declarative user interfaces and AI coding assistants to accelerate development.

Rather than treating the migration as a routine UI modernization project, the Instagram Direct team approached the transition through the lens of AI-readiness. The resulting codebase is fifty percent smaller than the original implementation. Furthermore, the architectural shift yielded a thirty-two percent reduction in engineer-agent exchanges, a thirty-five percent drop in AI agent execution time, and a thirty-three percent reduction in token costs. In close partnership with Google, these engineering performance optimizations were fed back into the core framework, enhancing Jetpack Compose not just for Instagram, but for the wider Android developer ecosystem.

Modernizing the Codebase at Massive Scale

Artificial intelligence has rapidly become an everyday companion for software engineers across the technology industry. Applying AI tools to massive codebases typically yields immediate productivity gains, but the Instagram Direct team set a far more ambitious objective. Instead of simply retrofitting AI tools onto existing legacy code, the team redesigned the codebase and its architecture to be AI-native from the ground up, multiplying the impact of automation far beyond what standard code generation could achieve.

How Instagram Direct engineers built AI-native UI architecture with Jetpack Compose and reduced token cost per agent session by 33% | Android Developers' Blog

Jetpack Compose served as a foundational component for this new AI-native UI architecture. Because of its declarative nature, Compose ensures that code remains concise, highly predictable, and structurally easier for modern AI models to reason about. It introduces fewer side effects, diminishes implicit state management complexities, and establishes crystal-clear component boundaries.

Executing a migration of this magnitude across a platform utilized by hundreds of millions of people required meticulous planning. The transition had to be carried out gradually and seamlessly, ensuring zero disruption to the user experience while engineers entirely rebuilt the technical foundation underneath. The sheer scale of the challenge is underscored by the complexity of the interface: individual UI components can render in more than 160 distinct state permutations, and a single conversation screen manages upwards of 200 distinct message types.

When migrating large-scale codebases, engineering teams often face the temptation to take shortcuts, such as embedding Compose UI components directly inside an existing legacy View hierarchy. While acceptable as a temporary stepping stone during a transitional phase, long-term integration of Compose within a View-based architecture creates deep friction. AI tools naturally follow the path of least resistance. When imperative and declarative UI code are blended together, AI models frequently combine them incorrectly, inadvertently introducing subtle bugs, persistent technical debt, and performance regressions.

Building an AI-Native UI Architecture

At Instagram’s scale, architectural abstractions are unavoidable to keep the application maintainable as it expands. A classic pattern involves modeling every individual list item type as a descendant of a custom base class that exposes standard lifecycle hooks such as binding methods. However, blending imperative context with declarative lambdas can easily result in shared mutable states that survive re-bindings across multiple rows, leading to unpredictable bugs that are notoriously difficult to reproduce.

How Instagram Direct engineers built AI-native UI architecture with Jetpack Compose and reduced token cost per agent session by 33% | Android Developers' Blog

To make the codebase genuinely AI-friendly, the Instagram team established practical architectural rules that prevent AI models from bypassing safety boundaries. By structuring components so that all Compose UI logic lives strictly within constructors without direct access to mutable class members or external states, the components behave like pure functions while remaining fully compatible with existing architectural patterns.

Managing this transition required maintaining hundreds of UI components in parallel with their legacy counterparts for an extended period. AI workflows accelerated the generation of massive amounts of code, enabling the Direct team to perform the migration in record time without stalling the delivery of daily product features for millions of users. Multiple engineers deployed their own AI agents against a shared knowledge base of reusable conventions and skills established during the migration, keeping best practices synchronized across the entire team.

The empirical results of the migration validated this architectural strategy. For migrated Instagram Direct surfaces, Jetpack Compose allowed the team to cut the total amount of UI code in half. Internal data analysis comparing AI agent sessions working on Compose UI against identical tasks using Android Views demonstrated clear efficiency gains across output efficiency and token costs.

Furthermore, the data revealed a striking difference in how the two frameworks handle complex or fragile code. Meta tracks code health using a risk score that evaluates overall code quality and the probability of a change causing production incidents. As files accumulate higher risk scores, AI agent sessions naturally become less resource efficient. When a file’s accumulated risk score doubles, UI implemented with Android Views suffers a thirty percent reduction in agent resource efficiency per landed character. Under the exact same circumstances, the efficiency reduction for Jetpack Compose UI is only nine percent.

How Instagram Direct engineers built AI-native UI architecture with Jetpack Compose and reduced token cost per agent session by 33% | Android Developers' Blog

Performance Optimizations and the LazyColumn Transition

Because Instagram Direct is an integral part of the user experience, users expect the messaging interface to feel instantaneously fast and responsive. Adopting Jetpack Compose meant undertaking a substantial UI rewrite, and the primary directive was to preserve an exceptionally high performance bar without a single regression.

Years of iterative engineering had already pushed the legacy View-based implementation to peak performance. To meet that same standard with a brand-new UI framework, the team monitored thousands of metrics, focusing heavily on scroll jank, frame drops, and overall rendering latency. Evaluating these metrics through runtime production A/B testing revealed that small, incremental component migrations often paint an incomplete picture. The true performance benefits of Compose become fully visible only when an entire surface is migrated end-to-end without bridging interruptions.

The core screens of Instagram Direct rely on long lists of varied item types traditionally built on top of RecyclerView. While the team initially migrated hundreds of individual list items to Compose while keeping the underlying RecyclerView architecture intact, the ultimate step involved replacing the legacy list core with Compose-native alternatives like LazyColumn.

To achieve this safely, the team engineered an interop API that allowed new Compose items to remain compatible with both RecyclerView and LazyColumn simultaneously. This dual-compatibility layer allowed engineers to roll out LazyColumn setups under rigorous A/B tests side-by-side with RecyclerView, reusing identical Compose elements and polishing performance without disrupting feature development.

How Instagram Direct engineers built AI-native UI architecture with Jetpack Compose and reduced token cost per agent session by 33% | Android Developers' Blog

This close technical collaboration between Google and Meta also spurred direct enhancements to the Jetpack Compose framework itself. Addressing Instagram’s strict performance thresholds led to the introduction of advanced framework capabilities, notably pausable composition enabled by LazyLayoutCacheWindows and precise visibility tracking.

Pausable composition, which is enabled by default in recent versions of Compose, allows expensive lazy-list items to be composed incrementally across multiple frames to prevent visual jank. When paired with the LazyLayoutCacheWindow API, scroll smoothness improves significantly. Internal testing at Meta demonstrated that combining pausable composition with a one-viewport LazyLayoutCacheWindow reduced large frame drops per minute by roughly thirteen percent compared to standard Compose implementations.

The Cache Window mechanism prepares and retains off-screen items within a specific pixel-based band around the viewport, facilitating fast flings and smooth scrolling transitions. Additionally, the introduction of the onVisibilityChanged API provided large-scale Compose surfaces with a standardized, reliable method to detect when a composable is genuinely visible on screen, replacing custom, hand-rolled tracking implementations previously scattered across hundreds of files.

Startup Performance and Broader Lessons

Beyond the immediate improvements within Instagram Direct, adopting Jetpack Compose triggered unexpected performance benefits across other areas of the application. The Jetpack Compose runtime carries a warmup cost that applications pay only once. Because messaging represents a high-traffic surface frequently accessed early in a user session, other parts of the Instagram app relying on Compose inherited noticeable performance gains. Startup performance within Instagram Direct itself was further optimized through the strategic use of Baseline Profiles, which pre-compile critical code paths at install time to ensure rapid rendering from the very first launch.

How Instagram Direct engineers built AI-native UI architecture with Jetpack Compose and reduced token cost per agent session by 33% | Android Developers' Blog

The successful migration of Instagram Direct demonstrates that transitioning to Jetpack Compose offers advantages far beyond simplified UI code. By aligning architectural choices with the operational patterns of modern AI assistants, engineering teams can achieve dramatic reductions in codebase size while drastically improving developer productivity and resource efficiency. The ongoing partnership between Google and Meta continues to yield framework improvements designed to benefit developers and users across the entire Android ecosystem.