Skip to content

Conversation

Aniket-pd
Copy link
Contributor

@Aniket-pd Aniket-pd commented Sep 26, 2025

📜 Tickets

Jira ticket
Github issue

💡 Description

This PR introduces caching for homepage layout measurements to reduce redundant recalculations:

  • Added LayoutMeasurementCache helper to store previously computed section measurements (Top Sites, Stories, Search Bar).
  • Normalized width-dependent cache keys so identical inputs reuse cached values instead of rebuilding views.
  • Introduced keyed header-height caching and shared tallest-cell results for Stories so both section layout and spacer sizing reuse the same computation.

Motivation: Homepage refreshes often repeat the same state (same width, same visibility). Without caching, expensive layout work and view instantiation happens repeatedly. With this change, redundant work is skipped, improving CPU efficiency and reducing layout thrash.

this PR only affects internal performance

📝 Checklist

  • I filled in the ticket numbers and a description of my work
  • I updated the PR name to follow our PR naming guidelines
  • I ensured unit tests pass and wrote tests for new code
  • If working on UI, I checked and implemented accessibility (Dynamic Text and VoiceOver)
  • If adding telemetry, I read the data stewardship requirements and will request a data review
  • If adding or modifying strings, I read the guidelines and will request a string review from l10n
  • If needed, I updated documentation and added comments to complex code

Introduces caching for layout measurements of Top Sites, Stories, and Search Bar sections to improve performance and avoid redundant calculations. Refactors section height calculations to utilize cached values and adds normalization for dimension keys. Also adds header height caching for more efficient layout updates.
@Aniket-pd Aniket-pd requested a review from a team as a code owner September 26, 2025 00:53
@Aniket-pd Aniket-pd requested a review from ih-codes September 26, 2025 00:53
@lmarceau lmarceau changed the title FXIOS-29124: [Homepage Layout] Cache section measurements to avoid redundant recalculations Refactor FXIOS-13400 [Homepage Layout] Cache section measurements to avoid redundant recalculations Sep 26, 2025
@mobiletest-ci-bot
Copy link

Messages
📖 Project coverage: 37.35%

🧹 Tidy commit

Just 1 file(s) touched. Thanks for keeping it clean and review-friendly!

🙌 Friday high-five

Thanks for pushing us across the finish line this week! 🙌

💬 Description craftsman

Great PR description! Reviewers salute you 🫡

Client.app: Coverage: 37.23

File Coverage
HomepageSectionLayoutProvider.swift 19.22% ⚠️

Generated by 🚫 Danger Swift against 373e06c

@Aniket-pd Aniket-pd closed this Sep 26, 2025
@Aniket-pd Aniket-pd deleted the 29124-homepage-layout-fix branch September 26, 2025 18:17
@ih-codes
Copy link
Collaborator

Hi @Aniket-pd , I see you just closed this. FYI I was actively testing your fix locally by removing the workaround check we had originally put in place in the HomepageViewController:
Screenshot 2025-09-26 at 12 22 15 PM

For some background context, we had to add that check because some spammed redux actions elsewhere in the codebase were causing performance issues in the diffable data source when re-rendering and computing its layout every snapshot update. The repeated cell dequeuing for height calculations caused hangs when scrolling on websites like Mashable (specifically on individual articles).

Anyway, I tested in the sim and profiled your changes in Xcode and I definitely saw a performance improvement. I didn't look into the code yet though, as @Foxbolts is more familiar with that area. You can tag us both if you reopen this PR later!

@Aniket-pd Aniket-pd restored the 29124-homepage-layout-fix branch September 26, 2025 18:48
@Aniket-pd Aniket-pd reopened this Sep 26, 2025
@Aniket-pd
Copy link
Contributor Author

Hey, I accidentally closed this earlier ,my bad!
I’ve reopened it now. @ih-codes @Foxbolts could you please give it a review when you have a moment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants