Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

[Performance improvements] Refactor SettingsListItem #186

Merged
merged 5 commits into from
Jun 22, 2020

Conversation

guidezpl
Copy link
Member

@guidezpl guidezpl commented Jun 18, 2020

This PR refactor SettingsListItem for performance.

  • Only creates a RadioListTile for those visible items instead of all of them
  • Limits the container height so that only 8 list items can be visible at once. This really only affects the behavior for the locale setting.

Closes #46

Web startup performance

Before After
before after

Screenshot 2020-06-18 at 23 03 53

Screenshot 2020-06-18 at 21 35 34

@guidezpl guidezpl requested a review from clocksmith June 19, 2020 10:55

final LinkedHashMap<T, DisplayOption> optionsMap;

/// For ease of use. Correspond to the keys and values of [optionsMap].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like breaking the map into these 2 Iterables doesn't add much value. I suggest removing them.

If you think they should remain, then please make them private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing data structure operations felt kind of wrong in the build method, although that's purely based on feeling. I'll see to moving this to the _State class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a bit of reading on these things and because it's implemented as a hash map + doubly linked list, obtaining the keys/values is inexpensive.

return AnimatedBuilder(
animation: _controller.view,
builder: _buildHeaderWithChildren,
child: Container(
constraints: const BoxConstraints(maxHeight: 380),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is this the real crux of the fix? Just capping the height?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe most of the gains are gotten through this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since 380 / 8 = 47.5, and if this is to show exactly 8 items, should it maybe be something like 384? (maybe the height of the item is 48?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this makes it fit perfectly

Copy link
Contributor

@clocksmith clocksmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very simple fix for great gains!

@guidezpl guidezpl merged commit b631481 into master Jun 22, 2020
@guidezpl guidezpl deleted the fix-settings-locale-list branch June 22, 2020 17:34
guidezpl added a commit that referenced this pull request Jun 27, 2020
* Limit Settings list item height

* Renaming

* Make optionsMap keys & values private

* Set correct height

Former-commit-id: b631481
DanTup pushed a commit to DanTup/flutter_gallery that referenced this pull request Jun 30, 2020
* Add snackbars demo


Former-commit-id: 6410ee6
@guidezpl guidezpl changed the title [Performance] Refactor SettingsListItem [Performance improvements] Refactor SettingsListItem Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Performance] Settings locale list initial load is slow (3)
3 participants