TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Auto Layout Performance on iOS

42 点作者 Garthex大约 12 年前

5 条评论

skue大约 12 年前
I wish this article spent more time discussing how autolayout is implemented in the real-life example, and less time talking about absurd situations such as using autolayout with a thousand subviews.<p>We are given no info about what constraints were used and whether the view was created in code or IB. For all we know, maybe all they needed was an extra constraint or two they to speed things up. Diving into how changing individual constraints affects overall performance would be interesting. It would be nice if Instruments had a template for inspecting autolayout performance (or does it? I haven't looked and not by my desktop).<p>Also, the numbers without autolayout still aren't great (hopefully that was tested on low end hardware?). I wonder why the OP didn't just pre-render the next view in the background, since he has the luxury of knowing that users will page through views in a linear fashion.
评论 #5618865 未加载
evadne大约 12 年前
Practicing latency hiding techniques might be useful here. Try grabbing a first generation iPhone and scroll really fast in Safari, for example — you’ll see a checker grid underneath the actual content. iOS interaction emphasizes movement and fluidity over visual clarity or pixel perfectness; while it is actually acceptable to drop granularity it is usually frowned upon to drop frames. Our Choice (the famous Al Gore book on iOS by Push Pop Press) does the same thing. iBooks does the same thing (PDF only; its ePUB part just chokes). Even GoodReader does the same thing.<p>Several general strategies off the back of my hand: a) precompute images in the background, store and decode the important bits on the fly; b) use proxy images unless the card is visible; c) a combination of both. Sounds like a fun problem (for solving it the first time).<p>On layout — Autolayout is slow, period. On a collection view with square cells of identical sizes, autolayout takes over five seconds to make up its mind. (This is from a random iPhone 4S.) If your design is not super flexible, it might make sense to set up a few styles up front and reuse them again and again. Even drawing unstyled text into framebuffers is heavy if you do it often on dynamically generated content. (For example, 72 small labels for a scrolling date picker chokes at &#60;30FPS.) Sometimes it’s better to design the issue away. Even a well-written piece of software may look awkward and work clumsily when it resizes during rotation while a square thing will generally work. The last ditch is to crossfade, but I digress.<p>The last thing I think is very relevant: layout taking a long time is actually also not a big deal if you only do the initial layout for two or three views you end up reusing. Small, frequent memory allocation (and drawing) during human interaction kills the joy. Hopefully, if you’re using an UIPageViewController, you’re also reusing the view controllers and its views.<p>Side note: I have not seen a great way to cancel work halfway done or is no longer necessary on iOS at the library / framework level. NSOperation has cancellation support which is basically twiddling glorified (hopefully) thread-safe boolean flags that get checked periodically. Sometimes people decide to throw the results away in the completion handler.
rmrfrmrf大约 12 年前
More or less what I expected -- I thought it was common knowledge that anything code-related with "auto" in it is going to have some significant overhead, as you can pretty much guarantee that there is a ton of looping going on.
phil大约 12 年前
Those look like parabolas, which implies that there's something O(n^2) going on. Since autolayout has to evaluate each constraint against the other constraints, this shouldn't be too surprising.<p>Like other commenters, I find the 1,000 subview test runs pretty silly. (Pro tip: if you need to put thousands of things on the screen, you don't want to give each one its own view. They aren't that light no matter how you lay them out).<p>This stuff is pretty clearly optimized for use with a handful to a few dozen views. It would be great to see a performance comparison for that range.
coldcode大约 12 年前
I've found auto-layout to be less than useful much of the time, often you are left with puzzlement as to what's wrong, leading to turning it off and doing something else.