Skip to content

Conversation

@abarth
Copy link
Contributor

@abarth abarth commented Jan 20, 2017

This patch aligns the iteration patterns used by animations and
ChangeNotifier. They now both respect re-entrant removal of listeners
and coalesce duplication registrations. (Also, ChangeNotifier
notification is no longer N^2).

This patch introduces ObserverList to avoid the performance regression that the
previous version of this patch caused.

Fixes #7533

This patch aligns the iteration patterns used by animations and
ChangeNotifier. They now both respect re-entrant removal of listeners
and coalesce duplication registrations. (Also, ChangeNotifier
notification is no longer N^2).

This patch introduces ObserverList to avoid the performance regression that the
previous version of this patch caused.

Fixes flutter#7533
@abarth
Copy link
Contributor Author

abarth commented Jan 20, 2017

@Hixie

Attempt 2

assert(_debugAssertNotDisposed);
if (_listeners != null) {
List<VoidCallback> localListeners = new List<VoidCallback>.from(_listeners);
final List<VoidCallback> localListeners = new List<VoidCallback>.from(_listeners);
Copy link
Contributor

Choose a reason for hiding this comment

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

it's tempting to suggest we should do a copy-on-write during iteration here, since we now control this more closely.

but that's probably a premature optimisation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'd prefer to wait to see this show up on a profile.

@Hixie
Copy link
Contributor

Hixie commented Jan 20, 2017

LGTM

Please file a bug (or comment on an existing bug) or add a TODO about adding documentation about the fact that you'll get called a surprising number of times if you remove yourself while iterating but you added yourself to multiple listenables that all ended up deferring to the same change notifier.

@abarth
Copy link
Contributor Author

abarth commented Jan 20, 2017

I filed #7570 so we don't lose track of it.

@abarth abarth merged commit 0f1d977 into flutter:master Jan 20, 2017
@abarth abarth deleted the iteration_patterns_redux branch January 20, 2017 23:38
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
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.

AnimationController notifies listeners removed during iteration

3 participants