Masonry Layout Framework: Bundle Size Impact and Optimization Solutions
Masonry, a lightweight iOS layout framework, simplifies constraints with chainable syntax but its block‑based APIs can add several megabytes to an app’s bundle when heavily used; replacing those blocks with non‑block alternatives reduces the size increase to roughly one kilobyte, preserving performance.
Masonry is a lightweight framework frequently used for UI layout in iOS development. It simplifies the usage of NSLayoutConstraint by allowing developers to specify constraints in a chain-like manner.
Impact on Bundle Size: Masonry uses blocks as parameters for constraint definitions. When a project extensively uses Masonry for layout, it results in numerous blocks. Since blocks are essentially structs, this increases code volume and consequently the app bundle size. Through testing with a demo project: using Frame-based layout results in a binary file size of 100KB, while using Masonry increases it to 103KB (a 3KB increase). If the entire project uses Masonry, the bundle size could increase by several megabytes.
Improved Solution: For developers who want to use Masonry but prefer to avoid blocks, the article provides a modified Masonry source code approach. By replacing block-based APIs with non-block alternatives, the bundle size impact becomes negligible. Testing shows the binary file size remains at approximately 101KB, which is only 1KB more than the Frame-based approach.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.