Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perf on system fonts #94826

Closed
wants to merge 2 commits into from
Closed

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Dec 7, 2021

This is on a hot path when building lots of text widgets. At least in part because of dart-lang/sdk#47873, it's significantly slower than change notifier. Running a benchmark that builds lots of text widgets in a tight loop shows improvement from this change.

This also had behavior that's slightly different from "regular" change notifiers previously, because it didn't use identity hash coding on closures, and so would allow multiple additions without calling back multiple times.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Dec 7, 2021
void removeListener(VoidCallback listener) {
_systemFontsCallbacks.remove(listener);
}
class _SystemFontsNotifier extends ChangeNotifier {
Copy link
Contributor

@chunhtai chunhtai Dec 7, 2021

Choose a reason for hiding this comment

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

the changeNotifier uses list and the text renderobject add/remove itself in attach and detach, it may depends on how you test it there may be performance regression as well. Is it possible to override the hashcode method of the closure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. Attach and detach might not be the right place for this - now that RO has dispose, perhaps we should move it to creation and disposal?

Copy link
Contributor

@chunhtai chunhtai Dec 7, 2021

Choose a reason for hiding this comment

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

Can you explain more? the detached RO doesn't need to be notified about font change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh ok. I'm running a benchmark like this: https://gist.github.com/dnfield/51b8f5ee3a0439b47d2841fc688d95c6, where this change is showing significant improvement.

I'll try this change out in a larger "real application" benchmark as well though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In flutter_gallery__transitions_perf on both a Android Go and a Pixel 4 device, this all seems to be lost in noise. It improve the microbenchmark but not the real application benchmark.

Given that, I'd be fine with just waiting on a fix for hashing closures in the upstream Dart SDK.

@dnfield dnfield closed this Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants