理解和提升 SwiftUI 性能

[

[

Cal Stephens

](https://medium.com/@calstephens98?source=post_page---byline--37b77ac61896---------------------------------------)

](https://medium.com/@calstephens98?source=post_page---byline--37b77ac61896---------------------------------------)

New techniques we’re using at Airbnb to improve and maintain performance of SwiftUI features at scale

我们在 Airbnb 使用的新技术,以提高和维护大规模 SwiftUI 功能的性能

By Cal Stephens, Miguel Jimenez

Cal StephensMiguel Jimenez

Airbnb first adopted SwiftUI in 2022, starting with individual components and later expanding to entire screens and features. We’ve seen major improvements to engineers’ productivity thanks to its declarative, flexible, and composable architecture. However, adopting SwiftUI has brought new challenges related to performance. For example, there are many common code patterns in SwiftUI that can be inefficient, and many small papercuts can add up to a large cumulative performance hit. To begin addressing some of these issues at scale, we’ve created new tooling for proactively identifying these cases and statically validating correctness.

Airbnb 在2022年首次采用SwiftUI,最初从单个组件开始,后来扩展到整个屏幕和功能。由于其声明式、灵活和可组合的架构,我们看到工程师的生产力有了显著提高。然而,采用SwiftUI带来了与性能相关的新挑战。例如,SwiftUI中有许多常见的代码模式可能效率低下,许多小问题可能累积成较大的性能损失。为了开始在规模上解决这些问题,我们创建了新的工具,主动识别这些情况并静态验证正确性。

SwiftUI feature architecture at Airbnb

Airbnb 的 SwiftUI 特性架构

We’ve been leveraging declarative UI patterns at Airbnb for many years, using our UIKit-based Epoxy library and unidirectional data flow systems. When adopting SwiftUI in our screen layer, we decided to continue using our existing unidirectional data flow library. This simplified the process of incrementally adopting SwiftUI within our large codebase, and we find it improves the quality and maintainability of features.

多年来,我们在Airbnb利用声明式UI模式,使用基于UIKit的Epoxy库单向数据流系统。当我们在屏幕层采用SwiftUI时,我们决定继续使用现有的单向数据流库。这简化了在我们庞大的代码库中逐步采用SwiftUI的过程,我们发现这提高了功能的质量和可维护性。

However, we noticed that SwiftUI features using our unidirectional data flow library didn’t perform as well as we expected, and it wasn’t immediately ob...

开通本站会员,查看完整译文。

Главная - Вики-сайт
Copyright © 2011-2025 iteam. Current version is 2.144.0. UTC+08:00, 2025-06-26 07:10
浙ICP备14020137号-1 $Гость$