[go: nahoru, domu]

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

Delay default font manager to run concurrently with isolate setup #29291

Merged
merged 2 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Delay default font manager to run concurrently with isolate setup
  • Loading branch information
dnfield committed Oct 21, 2021
commit cdd461b2bb93cf855caf3c26bb3f23834369bf9c
6 changes: 6 additions & 0 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ std::weak_ptr<DartIsolate> DartIsolate::SpawnIsolate(
GetIsolateGroupData().GetIsolateSnapshot(), //
std::move(platform_configuration), //
flags, //
nullptr, //
isolate_create_callback, //
isolate_shutdown_callback, //
dart_entrypoint, //
Expand All @@ -118,6 +119,7 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
fml::RefPtr<const DartSnapshot> isolate_snapshot,
std::unique_ptr<PlatformConfiguration> platform_configuration,
Flags isolate_flags,
fml::closure root_isolate_create_callback,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback,
std::optional<std::string> dart_entrypoint,
Expand Down Expand Up @@ -177,6 +179,10 @@ std::weak_ptr<DartIsolate> DartIsolate::CreateRunningRootIsolate(
return {};
}

if (root_isolate_create_callback) {
root_isolate_create_callback();
}

if (settings.root_isolate_create_callback) {
// Isolate callbacks always occur in isolate scope and before user code has
// had a chance to run.
Expand Down
10 changes: 9 additions & 1 deletion runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ class DartIsolate : public UIDartState {
/// @param[in] isolate_configuration The isolate configuration used to
/// configure the isolate before
/// invoking the entrypoint.
/// @param[in] root_isolate_create_callback A callback called after the root
/// isolate is created, _without_
/// isolate scope. This gives the
/// caller a chance to finish any
/// setup before running the Dart
/// program, and before any embedder
/// callbacks in the settings object.
/// @param[in] isolate_create_callback The isolate create callback. This
/// will be called when the before the
/// main Dart entrypoint is invoked in
Expand All @@ -186,7 +193,7 @@ class DartIsolate : public UIDartState {
/// isolate is still running at this
/// point and an isolate scope is
/// current.
/// @param[in] context Engine-owned state which is
/// @param[in] context Engine-owned state which is
/// accessed by the root dart isolate.
/// @param[in] spawning_isolate The isolate that is spawning the
/// new isolate. See also
Expand All @@ -202,6 +209,7 @@ class DartIsolate : public UIDartState {
fml::RefPtr<const DartSnapshot> isolate_snapshot,
std::unique_ptr<PlatformConfiguration> platform_configuration,
Flags flags,
fml::closure root_isolate_create_callback,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback,
std::optional<std::string> dart_entrypoint,
Expand Down
5 changes: 5 additions & 0 deletions runtime/dart_isolate_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) {
vm_data->GetIsolateSnapshot(), // isolate snapshot
nullptr, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root_isolate_create_callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback
"main", // dart entrypoint
Expand Down Expand Up @@ -97,6 +98,7 @@ TEST_F(DartIsolateTest, SpawnIsolate) {
vm_data->GetIsolateSnapshot(), // isolate snapshot
nullptr, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root_isolate_create_callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback
"main", // dart entrypoint
Expand Down Expand Up @@ -170,6 +172,7 @@ TEST_F(DartIsolateTest, IsolateShutdownCallbackIsInIsolateScope) {
vm_data->GetIsolateSnapshot(), // isolate snapshot
nullptr, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root_isolate_create_callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback
"main", // dart entrypoint
Expand Down Expand Up @@ -392,6 +395,7 @@ TEST_F(DartIsolateTest, CanCreateServiceIsolate) {
vm_data->GetIsolateSnapshot(), // isolate snapshot
nullptr, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root_isolate_create_callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback
"main", // dart entrypoint
Expand Down Expand Up @@ -490,6 +494,7 @@ TEST_F(DartIsolateTest, InvalidLoadingUnitFails) {
vm_data->GetIsolateSnapshot(), // isolate snapshot
nullptr, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root_isolate_create_callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback
"main", // dart entrypoint
Expand Down
1 change: 1 addition & 0 deletions runtime/dart_lifecycle_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static std::shared_ptr<DartIsolate> CreateAndRunRootIsolate(
vm.GetIsolateSnapshot(), // isolate_snapshot
{}, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root isolate create callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback,
entrypoint, // dart entrypoint
Expand Down
2 changes: 2 additions & 0 deletions runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ tonic::DartErrorHandleType RuntimeController::GetLastError() {

bool RuntimeController::LaunchRootIsolate(
const Settings& settings,
fml::closure root_isolate_create_callback,
std::optional<std::string> dart_entrypoint,
std::optional<std::string> dart_entrypoint_library,
std::unique_ptr<IsolateConfiguration> isolate_configuration) {
Expand All @@ -369,6 +370,7 @@ bool RuntimeController::LaunchRootIsolate(
isolate_snapshot_, //
std::make_unique<PlatformConfiguration>(this), //
DartIsolate::Flags{}, //
root_isolate_create_callback, //
isolate_create_callback_, //
isolate_shutdown_callback_, //
dart_entrypoint, //
Expand Down
7 changes: 7 additions & 0 deletions runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class RuntimeController : public PlatformConfigurationClient {
/// Launch an isolate in that runtime controller instead.
///
/// @param[in] settings The per engine instance settings.
/// @param[in] root_isolate_create_callback A callback invoked before the
/// root isolate has launched the Dart
/// program, but after it has been
/// created. This is called without
/// isolate scope, and before any root
/// isolate callback in the settings.
/// @param[in] dart_entrypoint The dart entrypoint. If
/// `std::nullopt` or empty, `main` will
/// be attempted.
Expand All @@ -133,6 +139,7 @@ class RuntimeController : public PlatformConfigurationClient {
///
[[nodiscard]] bool LaunchRootIsolate(
const Settings& settings,
fml::closure root_isolate_create_callback,
std::optional<std::string> dart_entrypoint,
std::optional<std::string> dart_entrypoint_library,
std::unique_ptr<IsolateConfiguration> isolate_configuration);
Expand Down
17 changes: 10 additions & 7 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,22 @@ Engine::RunStatus Engine::Run(RunConfiguration configuration) {

UpdateAssetManager(configuration.GetAssetManager());

// If the embedding prefetched the default font manager, then set up the
// font manager later in the engine launch process. This makes it less
// likely that the setup will need to wait for the prefetch to complete.
if (settings_.prefetched_default_font_manager) {
SetupDefaultFontManager();
}

if (runtime_controller_->IsRootIsolateRunning()) {
return RunStatus::FailureAlreadyRunning;
}

// If the embedding prefetched the default font manager, then set up the
// font manager later in the engine launch process. This makes it less
// likely that the setup will need to wait for the prefetch to complete.
auto root_isolate_create_callback = [&]() {
if (settings_.prefetched_default_font_manager) {
SetupDefaultFontManager();
}
};

if (!runtime_controller_->LaunchRootIsolate(
settings_, //
root_isolate_create_callback, //
configuration.GetEntrypoint(), //
configuration.GetEntrypointLibrary(), //
configuration.TakeIsolateConfiguration()) //
Expand Down
1 change: 1 addition & 0 deletions testing/dart_isolate_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ std::unique_ptr<AutoIsolateShutdown> RunDartCodeInIsolateOnUITaskRunner(
vm_data->GetIsolateSnapshot(), // isolate snapshot
nullptr, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root isolate create callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback
entrypoint, // entrypoint
Expand Down
1 change: 1 addition & 0 deletions third_party/tonic/tests/dart_state_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TEST_F(DartState, IsShuttingDown) {
vm_data->GetIsolateSnapshot(), // isolate snapshot
nullptr, // platform configuration
DartIsolate::Flags{}, // flags
nullptr, // root_isolate_create_callback
settings.isolate_create_callback, // isolate create callback
settings.isolate_shutdown_callback, // isolate shutdown callback
"main", // dart entrypoint
Expand Down