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

Request DartPerformanceMode.latency during transitions #110600

Merged
merged 15 commits into from Sep 7, 2022

Conversation

iskakaushik
Copy link
Contributor

This change makes it so that a call is made to request the latency performance mode, added in flutter/engine#35614 during transitions. It is to be noted that any requests made to this are not guaranteed to be honored.

This is an initial version of the change where there are no guardrails against indefinitely requesting the latency performance mode, these will be added as needed in follow-up PRs.

@flutter-dashboard flutter-dashboard bot added f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels. labels Aug 30, 2022
@iskakaushik
Copy link
Contributor Author

Is there a way to ignore a test file for web platform?

@jonahwilliams
Copy link
Member

skip: kIsWeb ?

@jonahwilliams
Copy link
Member

The problem is a compile error, ui.DartPerformanceMode is missing members on the web implementation. You'll need to add those in before this can land - and also file a bug for the API verification check missing it.

@iskakaushik
Copy link
Contributor Author

The problem is a compile error, ui.DartPerformanceMode is missing members on the web implementation. You'll need to add those in before this can land - and also file a bug for the API verification check missing it.

Done: flutter/engine#35806

@jonahwilliams
Copy link
Member

Once that rolls, you won't need to skip this on the web since its just a no-op there

packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
/// Even if the result is `true`, the engine may choose to ignore the request or
/// the performance mode may not be guaranteed to be the one requested.
///
/// If conflicting requests are made, only the first request will be honored.
Copy link
Member

Choose a reason for hiding this comment

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

Why the first? Shouldn't it be the "highest" one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the situation I was trying to guard against:

  1. C1 requests latency mode, and it is activated.
  2. C2 requests throughput mode, we will deny this request, and not record the request anywhere.

In the current design, the primary situation I'm concerned with is the transitions requesting latency mode. if there are multiple conflicting requests, I am not adding them to any queue, only one of two things are supported now:

  1. If no performance mode request is active, a component can request a specific performance mode.
  2. If a performance mode P is active, another component can extend the lease on only P until dispose is called.

I think supporting a queue of requests is not necessary for the use-case that I'm solving. Hope this answers #110600 (comment) as well.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Can you document that behavior on the method? And we can also simplify the implementation then. We only need to keep track of the active mode and how many handles we have given out for it. No need to imply with the implementation that we can keep track of different modes.

Also, as a side effect this means if somebody where to request balanced all other requests are blocked, which seems a little odd. When nobody has requested a mode we also run in balanced and we are happy to switch to any other mode.

packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
@@ -249,6 +257,8 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
_animation = createAnimation()
..addStatusListener(_handleStatusChanged);
assert(_animation != null, '$runtimeType.createAnimation() returned null.');
_performanceModeRequestHandle =
SchedulerBinding.instance.createPerformanceModeRequest(this, ui.DartPerformanceMode.latency);
Copy link
Member

Choose a reason for hiding this comment

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

nit: indent by two spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already indented with 2 spaces, maybe i'm missing something?

packages/flutter/lib/src/widgets/routes.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
/// Even if the result is `true`, the engine may choose to ignore the request or
/// the performance mode may not be guaranteed to be the one requested.
///
/// If conflicting requests are made, only the first request will be honored.
Copy link
Member

Choose a reason for hiding this comment

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

I see. Can you document that behavior on the method? And we can also simplify the implementation then. We only need to keep track of the active mode and how many handles we have given out for it. No need to imply with the implementation that we can keep track of different modes.

Also, as a side effect this means if somebody where to request balanced all other requests are blocked, which seems a little odd. When nobody has requested a mode we also run in balanced and we are happy to switch to any other mode.

packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM with some nits

packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/scheduler/binding.dart Outdated Show resolved Hide resolved
/// See also:
///
/// * [PerformanceModeRequestHandle] for more information on the lifecycle of the handle.
typedef PerformanceModeCleaupCallback = void Function();
Copy link
Member

Choose a reason for hiding this comment

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

Since this type isn't used anywhere, it can be a VoidCallback instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is still used in PerformanceModeRequestHandle, I think this typedef makes it easier to see when this callback will be invoked.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant that the type is not used in a public APi, so this can be private or use an existing type - right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, will change it to private.

iskakaushik and others added 5 commits September 6, 2022 11:09
Co-authored-by: Jonah Williams <jonahwilliams@google.com>
Co-authored-by: Jonah Williams <jonahwilliams@google.com>
Co-authored-by: Jonah Williams <jonahwilliams@google.com>
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

Comment on lines +186 to +191
/// This callback is invoked when a request for [DartPerformanceMode] is disposed.
///
/// See also:
///
/// * [PerformanceModeRequestHandle] for more information on the lifecycle of the handle.
typedef _PerformanceModeCleaupCallback = VoidCallback;
Copy link
Member

Choose a reason for hiding this comment

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

You can just delete this and use VoidCallback directly wherever _PerformanceModeCleaupCallback is currently used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's useful for the reader, makes it easy to understand that this type is called when the performance mode is resolved. Let me know if you feel strongly about it, and I can change it up in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants