Mobile Development 9 min read

Optimizing UITableView Scrolling Performance: Cell Height Caching and Asynchronous Text Rendering

This article explains how to achieve smooth iOS list scrolling by avoiding repeated cell height calculations and using asynchronous text rendering with YYText, providing code examples, performance trade‑offs, and profiling tips for mobile developers.

Tongcheng Travel Technology Center
Tongcheng Travel Technology Center
Tongcheng Travel Technology Center
Optimizing UITableView Scrolling Performance: Cell Height Caching and Asynchronous Text Rendering

In recent years, user experience has become paramount for apps, and smooth scrolling lists are essential; noticeable lag can lead to negative feedback or uninstalls.

Two major optimizations are presented: avoiding repeated cell height calculations and asynchronous text rendering.

Avoid Recalculating Cell Height

Calling heightForRowAtIndexPath: frequently can cause jank. In iOS 8 you can enable automatic dimension with self.tableView.estimatedRowHeight = 88; and self.tableView.rowHeight = UITableViewAutomaticDimension; , but for performance‑critical screens it's better to cache heights. Libraries such as UITableView‑FDTemplateLayoutCell provide a cache, or you can compute frames manually after data fetch and store them.

Example code shows how to pre‑compute frames and cell height in a FrameModel and return the cached value in heightForRowAtIndexPath: .

self.tableView.estimatedRowHeight = 88;
self.tableView.rowHeight = UITableViewAutomaticDimension;

Asynchronous Text Rendering

Rendering large amounts of text on the main thread is CPU‑intensive. Using a custom text view based on TextKit or Core Text, or the ready‑made YYText library, allows text layout to be prepared off‑screen and drawn asynchronously, reducing duplicate calculations and memory usage.

By replacing boundingRectWithSize: and sizeWithAttributes: with YYText’s layout methods, a FrameYYModel stores a YYTextLayout that provides pre‑computed size and attributes. The cell then sets titleLabel.textLayout = model.titleLayout; and enables displaysAsynchronously .

// FrameYYModel.m
- (void)setEntity:(FDFeedEntity *)entity {
    // ...
    YYTextContainer *titleContainer = [YYTextContainer containerWithSize:CGSizeMake(maxLayout, CGFLOAT_MAX)];
    _titleLayout = [YYTextLayout layoutWithContainer:titleContainer text:title];
    // ...
}

Both approaches have trade‑offs: cached height libraries simplify implementation but still incur Auto Layout overhead; manual frame calculation eliminates that overhead but requires more code. YYText offers smooth scrolling but may cause flicker when cells are refreshed asynchronously.

Additional tips include limiting the number of views with rounded corners and using Instruments’ Time Profiler to pinpoint performance bottlenecks.

Conclusion

Combining UITableView‑FDTemplateLayoutCell (or manual frame caching) with YYText yields the best list performance; choose the solution that fits your project’s time constraints and visual requirements.

PerformanceiOSAsync RenderingAuto LayoutUITableViewCell Height CachingYYText
Tongcheng Travel Technology Center
Written by

Tongcheng Travel Technology Center

Pursue excellence, start again with Tongcheng! More technical insights to help you along your journey and make development enjoyable.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.