Skip to content

Conversation

@gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Aug 30, 2019

Description

This re-lands my automatic focus highlight mode change that was reverted in #38866, and originally introduced in #37825.

The original caused a regression in the gallery transition performance benchmark. I tracked this down to adding and removing listeners (mostly removing) in the ObserverList that it used to track the listeners. I tried a number of things, but what it comes down to is that ObserverList is only efficient for small numbers of observers, and with the highlight mode change, it was getting hundreds of observers (even if they weren't being notified very often).

This adds a new HashedObserverList class that is based on a hash map that reference-counts the observer callbacks, and only notifies once for each callback. This can't be used in place of ObserverList in ChangeNotifier (the main use of ObserverList) because it makes things slower.

For small numbers of observers, the O(N) behavior of the remove method on ObserverList is not a problem, but because the constant for adding an item to a hash map is larger than the constant of appending an item to a small list, it would slow things down overall to use a HashMap for everything. It also would change the notification semantics, but internal Google tests indicate that that is not a problem, as most observers don't assume an order.

Also fixed two memory leaks that @ds84182 found in #38767.

Related Issues

#38860

Tests

  • Added tests for ObserverList and HashedObserverList.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.
  • I checked all the boxes!

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Aug 30, 2019
@gspencergoog gspencergoog added a: desktop Running on desktop and removed f: material design flutter/packages/flutter/material repository. labels Aug 30, 2019
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@gspencergoog gspencergoog merged commit f9bc899 into flutter:master Sep 4, 2019
@gspencergoog gspencergoog deleted the revert_highlight branch October 9, 2019 18:12
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: desktop Running on desktop framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants