Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Feb 28, 2022

fixes flutter/flutter#98591

This PR depends on flutter/flutter#98046.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@gaaclarke gaaclarke changed the title Background isolate dart registrant Add Dart entrypoint to execute the dart plugin registrant. Feb 28, 2022
@gaaclarke gaaclarke force-pushed the background-isolate-dart-registrant branch 6 times, most recently from 6328d18 to c6fa534 Compare March 1, 2022 22:26
@gaaclarke gaaclarke force-pushed the background-isolate-dart-registrant branch from c6fa534 to cacef01 Compare March 2, 2022 00:27
@gaaclarke gaaclarke marked this pull request as ready for review March 2, 2022 00:27
@gaaclarke gaaclarke requested a review from blasten March 2, 2022 00:27
@gaaclarke
Copy link
Member Author

gaaclarke commented Mar 2, 2022

I need to add a negative test too, right now it just has a positive test. I'll add that this morning as well as the web_ui definitions.

(edit: done)

@gaaclarke gaaclarke force-pushed the background-isolate-dart-registrant branch from 6e6a684 to 39a0c3c Compare March 2, 2022 19:02

/// Makes sure the that the Dart Plugin Registrant has been called for this
/// isolate. This can safely be executed multiple times on the same isolate,
/// but should not be called on the Root isolate.
Copy link

Choose a reason for hiding this comment

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

Is the app developer responsible for calling this method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, potentially plugin developers too.

Copy link

Choose a reason for hiding this comment

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

if the check _wasInitialized is moved to DartPluginRegistrant_EnsureInitialized, would it handle the root isolate case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, that wouldn't allow it to be called from the background isolates which is what we want. If we did that we'd have to keep a map between the isolate and a bool to determine if it was called or not. That would be a bit involved since it would mean uniquely identifying the isolate some how and exposing that to c++.

Copy link

Choose a reason for hiding this comment

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

C++ side could only check for the root isolate, and the dart side for the custom isolate. Maybe the map is cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we think that this is a problem, the easiest solution would be to transfer the bool into the _PluginRegistrant and making the registrant idempotent.

Copy link

Choose a reason for hiding this comment

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

sgtm

Copy link
Member Author

Choose a reason for hiding this comment

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

I filed an issue for it: flutter/flutter#99444

/// Helper functions for Dart Plugin Registrants.
class DartPluginRegistrant {
/// Makes sure the that the Dart Plugin Registrant has been called for this
/// isolate. This can safely be executed multiple times on the same isolate,
Copy link

Choose a reason for hiding this comment

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

what is an isolate in the web? a web worker? @yjbanov

@pragma('vm:entry-point')
void callDartPluginRegistrantFromBackgroundIsolate() async {
ReceivePort receivePort = ReceivePort();
Isolate isolate = await Isolate.spawn(dartPluginRegistrantIsolate, receivePort.sendPort);
Copy link

Choose a reason for hiding this comment

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

It would be great if the Dart C++ API supported registering a callback that triggers whenever a new isolate is spawn.

The main benefit is that it would keep DartPluginRegistrant.ensureInitialized() as implementation detail.

Copy link
Member Author

Choose a reason for hiding this comment

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

We want people to have the option of not calling the dart plugin registrant on background isolates though for performance reasons. If you are spawning an isolate to do background encryption you don't want to start executing whatever happens in whatever plugins you are using elsewhere in your app.

Copy link

Choose a reason for hiding this comment

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

right. Although, the registration phase in federated plugins is about binding to a specific implementation of the shared interface, so the cost might just be constructing that specific implementation object for the plugins that do have a Dart plugin registrant.

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM

@gaaclarke gaaclarke merged commit e37b910 into flutter:main Mar 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 3, 2022
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.

Dart plugin registration doesn't run in background isolates

2 participants