Skip to content

Bk/performance optimizations#158

Merged
bryankeller merged 8 commits into
masterfrom
bk/performance-optimizations
Jun 8, 2026
Merged

Bk/performance optimizations#158
bryankeller merged 8 commits into
masterfrom
bk/performance-optimizations

Conversation

@bryankeller

@bryankeller bryankeller commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Details

This is the first of three PRs to optimize MagazineLayout. I did extensive profiling, and found several hot spots.

For a collection view with 100,000 items in it, after this wave of optimizations, the time in prepare has been greatly reduced.

  • prepare on first load: 60ms -> 4.5ms (13x reduction)
  • prepare after invalidating all delegate layout values: 58ms -> 5ms (11x reduction)
  • prepare after rotating the device: 58ms -> 8μs (725x reduction lol)

The changes in this PR don't get us all the way to those numbers, but after all three are merged, we'll get the full benefits.

These are the optimizations:

  • Reuse a single IndexPath instance in hot paths
  • Avoid protocol conformance checks on every delegate access
  • Avoid relatively-expensive UIKit calls when reading the current modelState
  • Defer calculating frames in each section
  • Greatly reduces the amount of work when just updating the width of the collection view to something new

I'd suggest reviewing commit-by-commit - that should make it more clear what changes are related to certain optimizations.

How Has This Been Tested

Tested in demo app and Airbnb app. Additionally, all unit tests pass.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Perf fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@bryankeller bryankeller requested a review from brynbodayle June 6, 2026 00:02
@bryankeller bryankeller force-pushed the bk/performance-optimizations branch 2 times, most recently from c479981 to 90f58eb Compare June 6, 2026 05:35
@bryankeller bryankeller added the enhancement New feature or request label Jun 6, 2026
@bryankeller bryankeller force-pushed the bk/performance-optimizations branch 3 times, most recently from 3553fc0 to 2a4d1f5 Compare June 6, 2026 23:07
@bryankeller bryankeller force-pushed the bk/performance-optimizations branch 4 times, most recently from a314211 to 311acab Compare June 7, 2026 00:51
Comment thread MagazineLayout/Public/MagazineLayout.swift Outdated
Comment thread MagazineLayout/Public/MagazineLayout.swift Outdated
@bryankeller bryankeller force-pushed the bk/performance-optimizations branch from 311acab to 34e3b90 Compare June 8, 2026 20:42
@bryankeller

Copy link
Copy Markdown
Contributor Author

Fixed, thanks @brynbodayle !

@bryankeller bryankeller merged commit d89b2e5 into master Jun 8, 2026
1 check passed
@bryankeller bryankeller deleted the bk/performance-optimizations branch June 8, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants