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 12, 2022

Previously we'd shadow the main entrypoint which didn't work in release builds. Now we look for the registrant's presence at runtime to execute.

Companion framework PR: flutter/flutter#98046

The test for this is an integration tests that happens in the framework PR.

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.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@gaaclarke
Copy link
Member Author

@blasten friendly ping

}

Dart_Handle FindDartPluginRegistrantLibrary() {
// TODO(): Instead of finding this, it could be passed down from the tool.
Copy link

Choose a reason for hiding this comment

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

do you plan to work on this issue?

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. I have no data to suggest it's worthwhile.

Copy link

Choose a reason for hiding this comment

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

How do you envision passing this from the tool?

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 haven't thought about it. Maybe we could make it so the library has a unique name so we can look directly for it?

Copy link

Choose a reason for hiding this comment

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

ok. I'd suggest filing an issue, and including the general idea about how this should be solved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Dart_Handle libraries = Dart_GetLoadedLibraries();
intptr_t length = 0;
Dart_ListLength(libraries, &length);
for (intptr_t i = 0; i < length; ++i) {
Copy link

Choose a reason for hiding this comment

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

this grows with the number of packages, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right. I suspect the order of magnitude will never make this an issue. It depends on Dart's implementation of their API but linearly searching through a couple thousand strings shouldn't be significant. Most of the string comparisons will fail on the first char check.

Copy link
Contributor

Choose a reason for hiding this comment

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

For an internal customer, this resulted in a >300ms regression on startup time on low end Android devices.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't it more like ~275ms? I might be looking at the wrong thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, it was just under 300ms - a mean change of about 291ms on low end Android. This represented a 17% regression from before this patch. I think we should revert this.

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 force-pushed the find-plugin-registrant branch from b9c41d2 to 3a28e84 Compare February 28, 2022 19:00
@gaaclarke
Copy link
Member Author

@blasten can you give this another look. I decided to add an engine test. That will make the old code path easier to rip out once the engine PR lands.

@gaaclarke gaaclarke force-pushed the find-plugin-registrant branch from 3a28e84 to 6b5c7fe Compare February 28, 2022 19:04
bool didCallRegistrantBeforeEntrypoint = false;

// Test the Dart plugin registrant.
@pragma('vm:entry-point')
Copy link

Choose a reason for hiding this comment

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

is there any difference between this file (or test) and

@pragma('vm:entry-point')
class _PluginRegistrant {
@pragma('vm:entry-point')
static void register() {
if (didCallRegistrantBeforeEntrypoint) {
throw '_registerPlugins is being called twice';
}
didCallRegistrantBeforeEntrypoint = true;
}
}
@pragma('vm:entry-point')
void mainForPluginRegistrantTest() {
if (didCallRegistrantBeforeEntrypoint) {
passMessage('_PluginRegistrant.register() was called');
} else {
passMessage('_PluginRegistrant.register() was not called');
}
}
?

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, the path of the file. The other one can be removed once we land the Framework PR.

@gaaclarke gaaclarke force-pushed the find-plugin-registrant branch from 21f8dbc to 87f0eaa Compare February 28, 2022 21:47
@gaaclarke gaaclarke merged commit e97c801 into flutter:main Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 1, 2022
zanderso pushed a commit to flutter/flutter that referenced this pull request Mar 1, 2022
* e97c801 Started looking for the dart plugin registrant at runtime  (flutter/engine#31418)

* 9ebbc6e Standardize the embedder file name. (flutter/engine#31723)

* e983ac8 Roll Skia from 1fc0c1c0f8af to 5deac304821b (2 revisions) (flutter/engine#31725)

* afd334d added dart plugin registrant test executables to run_tests.py (flutter/engine#31726)

* 0ff508b Standardize embedder archive name. (flutter/engine#31693)

* 9c1daae Roll Fuchsia Mac SDK from qGsRXn7-D... to RIOZP5nXz... (flutter/engine#31730)

* ceec638 Roll Fuchsia Linux SDK from _mwyhkd9H... to 7rB0Yrprs... (flutter/engine#31731)

* 54050b4 Roll Skia from 5deac304821b to c3e7a2a00b0a (3 revisions) (flutter/engine#31732)

* a5718ab Roll Dart SDK from c3e3126a598b to 34a5563af80d (6 revisions) (flutter/engine#31734)
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Mar 8, 2022
* e97c801 Started looking for the dart plugin registrant at runtime  (flutter/engine#31418)

* 9ebbc6e Standardize the embedder file name. (flutter/engine#31723)

* e983ac8 Roll Skia from 1fc0c1c0f8af to 5deac304821b (2 revisions) (flutter/engine#31725)

* afd334d added dart plugin registrant test executables to run_tests.py (flutter/engine#31726)

* 0ff508b Standardize embedder archive name. (flutter/engine#31693)

* 9c1daae Roll Fuchsia Mac SDK from qGsRXn7-D... to RIOZP5nXz... (flutter/engine#31730)

* ceec638 Roll Fuchsia Linux SDK from _mwyhkd9H... to 7rB0Yrprs... (flutter/engine#31731)

* 54050b4 Roll Skia from 5deac304821b to c3e7a2a00b0a (3 revisions) (flutter/engine#31732)

* a5718ab Roll Dart SDK from c3e3126a598b to 34a5563af80d (6 revisions) (flutter/engine#31734)
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Mar 21, 2022
@gaaclarke
Copy link
Member Author

@alexmarkov we had to revert this because it caused a performance regression (300ms). This PR is related to the --source flag. Remember how it creates a library with a file uri? That's why I have to hunt for it.

You said in dart-lang/sdk#48144 (comment) that we could potentially make this generated code a package instead. If we got a package uri instead of a file uri we could look for it directly. Would that be your recommendation here?

It also seems unfortunate that this code take 300ms. It is essentially performing a couple thousand string comparisons. Maybe there is something we could do to speed that up.

If we go down the package route, how does one edit the .dart_tool/package_config.json? Is there an API for that or are you suggesting we open up that file and edit it directly?

@alexmarkov
Copy link
Contributor

@gaaclarke I'm not sure what is the best way to deal with generated sources - so consider talking to someone more familiar with source code generation. FWIW here are a few options I can suggest:

  • We can probably save the file URI of the generated file and pass it to the engine.
  • We can generate a file alongside the main.dart in lib directory and call it main.g.dart. In such case its URI can be constructed from the main library URI (e.g. if main is package:foo/main.dart, then the generated file will have package:foo/main.g.dart URI).
  • As suggested before, we can generate a separate package for the generated file. Although package_config.json is just a JSON file, I would recommend to take a look at https://pub.dev/packages/package_config to work with those files as their format can change over time.

gaaclarke added a commit that referenced this pull request Mar 21, 2022
@gaaclarke
Copy link
Member Author

@alexmarkov for option 1, could I compile the program with -Dflutter.dart_plugin_registrant=<file url> then use Dart_Invoke(string, "fromEnvironment", 1, "flutter.dart_plugin_registrant") from C++ to recall it?

It appears that's how FLUTTER_WEB_AUTO_DETECT works. It is a bit odd since I typically think of environment variables as being things defined at runtime, not compilation time.

@alexmarkov
Copy link
Contributor

alexmarkov commented Mar 22, 2022

@gaaclarke Not sure you can use Dart environment defines for that. They are specified at compile time and used to evaluate const String/int/bool.fromEnvironment(...) constructors at compile time. These constructors are not guaranteed to work when called at run time (https://github.com/dart-lang/sdk/blob/69d66d9bd5a4ba79bc9040a60ec9e93df0a25255/sdk/lib/core/string.dart#L167-L170). At run time VM forwards querying of the environment to the embedder (Flutter engine in case of Flutter), and Flutter engine doesn't seem to call Dart_SetEnvironmentCallback in order to implement that. So it's likely that String.fromEnvironment won't work if called at run time from Flutter app.

gaaclarke added a commit to gaaclarke/engine that referenced this pull request Mar 22, 2022
godofredoc added a commit that referenced this pull request Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants