Instagram Direct 将其 Android 用户界面从旧版的 Android View 系统迁移到了 Jetpack Compose,从而创建了一个 AI 原生的用户界面代码库,使 AI 编码代理更容易理解、修改和维护。据 Instagram 工程师称,这次迁移使用户界面的代码量减少了 50%,并将每个 AI 代理会话的 token 成本降低了 33%。
Instagram 工程师提出的一个关键观点是:“设计 AI 原生架构带来了显著的收益”。与其采取零敲碎打的方式(要求开发人员逐个迁移各个组件),不如把重点放在评估底层架构是否便于生成正确的实现方案上。事实上,正如他们指出的那样,“AI 工具往往会选择阻力最小的路径”,这很可能导致“隐蔽的 Bug、技术债务和性能退化”。
Instagram 的工程师们解释道,面向 AI 优化代码库,意味着在状态管理、可预测行为以及开发模式方面建立起正确的架构边界,从而使 AI 代理的“最小阻力路径”成为通向最佳转换效果的路径。他们的目标并非简单地让 AI 来弥补设计上的缺陷,而是基于对 AI 代理实际如何修改代码的理解来设计代码库:
AI 代理天生会选择阻力最小的路径,因此,在设计的时候就应该确保该路径最终生成正确且高质量的代码,同时让拙劣的设计决策难以实现且代价高昂。
另一个关键原则是最大限度地减少上下文依赖。也就是说,让 AI 代理不再依赖于特定代码库的知识,而是优先采用经过验证的最佳实践和熟悉的模式,从而帮助它们生成更可靠的结果。
这次迁移在不影响整个团队正常工作的前提下顺利完成,工程师能够在迁移期间继续发布新功能。AI 辅助工作流已经实现了标准化,这促进了一致性,并且可以确保与团队内部通用的架构规范和最佳实践保持一致。
通过这种方法,迁移到 Jetpack Compose 使 UI 代码量减少了 50%,同时将 AI 代理的执行时间缩短了 35%,每个代理会话的 token 成本降低了 33%,工程师与代理之间的交互次数减少了 32%。
一个主要的挑战是确保迁移不会导致性能退化。团队重点关注了三个关键的生产指标:交互响应时间,即打开屏幕后到其可用的时间;完全加载时间,即所有屏幕内容加载完成的时间;以及滚动性能,即衡量屏幕内容滚动的流畅程度。
在生产环境中,这些指标是通过运行时监控进行追踪,为的是能够进行 A/B 测试,可以将迁移后的 Compose UI 与旧版 UI 进行对比,并评估迁移对性能的影响。
Instagram 工程师的一个重要发现是:只有将整个屏幕迁移到 Compose 之后,才能可靠地评估性能,从而消除任何可能导致性能测量结果失真的遗留 View 组件。
这意味着 Compose UI 组件应该从其所在的框架中进行抽象,同时仍然需要与 RecyclerView 和 LazyColumn 保持兼容。同样重要的是,应该能够在运行时通过功能标志在这两者之间进行切换,以便进行 A/B 测试。
最终,团队使用 LazyColumn(Compose 中用于高效渲染可滚动列表的原生解决方案)替换了传统的 RecyclerView(最初是作为容纳新 Compose 可组合项的容器而被保留下来的)。
最后需要说明的是,这次迁移还提升了应用程序其他部分的启动性能。其中一部分原因在于,Compose 的运行时预热开销只需要在每个应用会话中承担一次,这样其他基于 Compose 的界面便可以利用已初始化的运行时环境,而不需要再次承担该开销。
原文链接:https://www.infoq.com/news/2026/10/instagram-compose-migration/
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Instagram Direct migrated its Android user interface from the old Android View system to Jetpack Company, creating an AI original user interface code repository that makes it easier for AI coding agents to understand, modify and maintain. According to Instagram engineers, the migration reduced the number of user interface codes by 50 per cent and the cost of token per AI proxy session by 33 per cent.
A key point made by Instagram Engineer was: “The design of the AI original structure brings significant benefits”. Rather than taking a piecemeal approach (which requires developers to move individual components), the focus should be on assessing whether the bottom-up architecture is conducive to generating the right delivery options. Indeed, as they have pointed out, “AI tools tend to choose the path of least resistance”, which is likely to lead to “hidden Bugs, technological debt and degradation of performance”.
Instagram's engineers explained that optimising the AI code library means setting the right structural boundaries for state management, predictable behaviour and development patterns, making the AI agent's “minimum resistance path” the path to optimal transformation. Their goal is not simply to let AI fill the design gap, but rather to design the code library based on an understanding of how AI agents actually change the code:
AI agents are born to choose the path with the least resistance and should therefore be designed in such a way as to ensure that the path eventually produces the correct and high-quality code, while making poor design decisions difficult and costly to achieve.
Another key principle is to minimize context dependency. In other words, instead of relying on the knowledge of a particular code repository, AI agents are given priority over proven best practices and familiar models to help them generate more reliable results.
The relocation was successfully completed without compromising the normal work of the entire team and the engineers were able to continue the new publish functionality during the migration. AI Supplementary workflow has been standardized, which promotes consistency and ensures consistency with corporate norms and best practices common within the team.
In this way, migration to Jetpack Company reduced the number of UI codes by 50 per cent, while reducing the execution time of AI agents by 35 per cent, the cost of token per proxy session by 33 per cent and the number of interactions between engineers and agents by 32 per cent.
A major challenge is to ensure that migration does not lead to degradation of performance. The team focused on three key production indicators: interactive response time, i.e., when the screen is open to its availability; full loading time, i.e., when all screen contents are loaded; and rolling performance, i.e. measuring the flow of screen content.
In the production environment, these indicators are tracked through operational monitoring to enable A/B tests to compare the migrationed Compose UI with the old version of UI and to assess the effects of migration on performance.
An important finding of the Instagram engineer is that the performance can only be reliably assessed if the entire screen is moved to Compose, thus eliminating any legacy of View components that could lead to a distortion of performance measurements.
This means that Compose UI components should be abstracted from the frame in which they are located, and still need to be compatible with RecyclerView and LazyColumn. It is also important to be able to switch between the two at the time of operation through functional markers in order to conduct A/B tests.
Finally, the team replaced the traditional RecyclerView (initially retained as a container to accommodate the new Compose combination) with LazyColumn (the primary solution for the efficient rendering of the scrollable list in Compose).
Finally, the migration also enhanced the start-up performance of other parts of the application. Part of the reason is that Compose ' s running preheating costs only take place once in each application session, so that other interfaces based on Compose can take advantage of the initialized running-time environment without having to bear the cost again.
Original link: https://www.infoq.com/news/2026/10/instagram-compoe-migration/
Auto-fetched and translated by AI Atlas. All rights belong to the original author.