← 回總覽

人人皆可参与的性能优化

📅 2026-04-09 00:01 Pinterest Engineering 软件编程 4 分鐘 4648 字 評分: 87
Android 性能工程 延迟 软件架构 Pinterest
📌 一句话摘要 Pinterest 工程团队分享了一种自动化测量“视觉完整”延迟的方法,通过将性能追踪直接集成到基础 UI 类中,显著降低了工程开销。 📝 详细摘要 本文详细介绍了 Pinterest 如何通过自动化测量“视觉完整”(Visually Complete)延迟来实现性能监控的普及化。此前,测量用户感知延迟需要为每个独立的 UI 界面编写定制化且难以维护的逻辑,每次实现大约需要耗费两周的工程师工时。性能团队通过将测量逻辑嵌入基础 UI 类(BaseSurface)解决了这一问题。通过定义通用的媒体视图接口(PerfImageView、PerfTextView、PerfVideo

Title: Performance for Everyone | BestBlogs.dev

URL Source: https://www.bestblogs.dev/article/c96b9d29

Published Time: 2026-04-08 16:01:01

Markdown Content: ![Image 1: Pinterest Engineering](https://medium.com/@Pinterest_Engineering?source=post_page---byline--21a560260d08---------------------------------------)

4 min read Just now

--

Author: Lin Wang (Android Performance Engineer)

Press enter or click to view image in full size

Default Feature

For mobile apps, performance is considered as the “default feature”, which means apps are expected to run fast and be responsive. It’s just as if we expect a watch to show the time. With no exceptions at Pinterest, we measure, protect and improve performance for all of our key user experiences’ surfaces, such as “Home Feed” and “Search Result Feed”.

Hard to Measure

Among all the performance metrics, the user perceived latency is a crucial one. It measures how much time the user spends since they perform an action until they see the content. This is also called “Visually Complete”. Visually Complete can be very different from app to app or even from surface to surface within one app. On Pinterest’s “Video Pin Closeup” surface, Visually Complete means the full-screen video starts playing; on our “Home Feed” surface, Visually Complete is defined as all the images rendered and videos playing; on our “Search Auto Complete Page”, Visually Completerefers to the search autocompleted suggestions’s text rendered along with the avatar images.

Press enter or click to view image in full size

Given this dynamic nature of Visually Complete, engineers had to create customized measurement logic for each surface and that takes a lot of engineering effort and maintenance cost. This ends up as a major boundary for general product engineers to work on performance, especially on newly created surfaces. On average, it takes two engineer-weeks to implement a User Perceived Latency metric on the Android Client and wire it up to all the toolsets for production usage.

All-In-One Solution

Over the years, the performance team at Pinterest has been thinking about how to offer performance measures with the lowest cost to product engineers. Therefore, more product engineers can more easily have access to their feature’s user perceived latency information and work on performance.

Until recently, it seems we have found an answer to this. In a nut shell, we built the Visually Complete logic into the base UI class (e.g. BaseSurface). Therefore, the Perceived Latencyof any UI surface (existing or new) will be automatically measured as long as the feature is built on top of this base UI class.

Walk the View Tree

First we define a few common media view interfaces: PerfImageView, PerfTextView, PerfVideoView. Each of them contains a few methods to report their rendering status: isDrawn(), isVideoLoadStarted(), x(),y(), height(), width(), etc.

Press enter or click to view image in full size

At the BaseSurface level, given that we should have access to the root android ViewGroup (e.g. RootView). We could just iterate through the view tree starting from the RootViewby visiting all the views on this tree. We will focus on those visible views and judge if all the PerfImageView, PerfTextView and PerfVideoView instances are all drawn or started if it’s a video.

Press enter or click to view image in full size

In Production

Since the release of this system on Android, it constantly visualizes the User Perceived Latency on over 60 surfaces at any given time. It is well received by many product teams and started to protect and improve their surface’s performance.

Press enter or click to view image in full size

Interesting Cases

* Since all surfaces are measured by the same standard, we can compare multiple surfaces’ performance fairly. * For some features with short shelf time (e.g. a Christmas landing page), we previously weren’t able to code their latency metrics in time, but now those latency metrics will be ready since the surface is built.

Conclusion

Once the performance metrics are offered to product engineers for free, it makes Pinterest’s performance more visible and encourages everyone to protect and optimize the User Perceived Latency on their surfaces.

Following the success on Android, we have also extended the same concept to iOS and web platforms.

Acknowledgements

Special thanks: Arun K

查看原文 → 發佈: 2026-04-09 00:01:01 收錄: 2026-04-09 02:00:30

🤖 問 AI

針對這篇文章提問,AI 會根據文章內容回答。按 Ctrl+Enter 送出。