forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We first add a PlatformMessageResponseDartComplete benchmark to test flutter#18838. Specifically, it improves from ~7600 us to ~1200 us after that PR on my MacBook Pro.
- Loading branch information
Showing
8 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/benchmarking/benchmarking.h" | ||
#include "flutter/common/settings.h" | ||
#include "flutter/lib/ui/window/platform_message_response_dart.h" | ||
#include "flutter/runtime/dart_vm_lifecycle.h" | ||
#include "flutter/shell/common/thread_host.h" | ||
#include "flutter/testing/dart_isolate_runner.h" | ||
#include "flutter/testing/fixture_test.h" | ||
|
||
#include <future> | ||
|
||
namespace flutter { | ||
|
||
class Fixture : public testing::FixtureTest { | ||
void TestBody() override{}; | ||
}; | ||
|
||
static void BM_PlatformMessageResponseDartComplete(benchmark::State& state) { | ||
ThreadHost thread_host("test", | ||
ThreadHost::Type::Platform | ThreadHost::Type::GPU | | ||
ThreadHost::Type::IO | ThreadHost::Type::UI); | ||
TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(), | ||
thread_host.raster_thread->GetTaskRunner(), | ||
thread_host.ui_thread->GetTaskRunner(), | ||
thread_host.io_thread->GetTaskRunner()); | ||
Fixture fixture; | ||
auto settings = fixture.CreateSettingsForFixture(); | ||
auto vm_ref = DartVMRef::Create(settings); | ||
auto isolate = | ||
testing::RunDartCodeInIsolate(vm_ref, settings, task_runners, "main", {}, | ||
testing::GetFixturesPath(), {}); | ||
|
||
while (state.KeepRunning()) { | ||
state.PauseTiming(); | ||
bool successful = isolate->RunInIsolateScope([&]() -> bool { | ||
// Simulate a message of 3 MB | ||
std::vector<uint8_t> data(3 << 20, 0); | ||
std::unique_ptr<fml::Mapping> mapping = | ||
std::make_unique<fml::DataMapping>(data); | ||
|
||
Dart_Handle library = Dart_RootLibrary(); | ||
Dart_Handle closure = | ||
Dart_GetField(library, Dart_NewStringFromCString("messageCallback")); | ||
|
||
auto message = fml::MakeRefCounted<PlatformMessageResponseDart>( | ||
tonic::DartPersistentValue(isolate->get(), closure), | ||
thread_host.ui_thread->GetTaskRunner()); | ||
|
||
message->Complete(std::move(mapping)); | ||
|
||
return true; | ||
}); | ||
FML_CHECK(successful); | ||
state.ResumeTiming(); | ||
|
||
// We skip timing everything above because the copy triggered by | ||
// message->Complete is a task posted on the UI thread. The following wait | ||
// for a UI task would let us know when that copy is done. | ||
std::promise<bool> completed; | ||
task_runners.GetUITaskRunner()->PostTask([&completed]{ | ||
completed.set_value(true); | ||
}); | ||
completed.get_future().wait(); | ||
} | ||
} | ||
|
||
BENCHMARK(BM_PlatformMessageResponseDartComplete) | ||
->Unit(benchmark::kMicrosecond); | ||
|
||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/testing/fixture_test.h" | ||
|
||
namespace flutter { | ||
namespace testing { | ||
|
||
FixtureTest::FixtureTest() | ||
: native_resolver_(std::make_shared<TestDartNativeResolver>()), | ||
assets_dir_(fml::OpenDirectory(GetFixturesPath(), | ||
false, | ||
fml::FilePermission::kRead)), | ||
aot_symbols_(LoadELFSymbolFromFixturesIfNeccessary()) {} | ||
|
||
Settings FixtureTest::CreateSettingsForFixture() { | ||
Settings settings; | ||
settings.leak_vm = false; | ||
settings.task_observer_add = [](intptr_t, fml::closure) {}; | ||
settings.task_observer_remove = [](intptr_t) {}; | ||
settings.isolate_create_callback = [this]() { | ||
native_resolver_->SetNativeResolverForIsolate(); | ||
}; | ||
settings.enable_observatory = false; | ||
SetSnapshotsAndAssets(settings); | ||
return settings; | ||
} | ||
|
||
void FixtureTest::SetSnapshotsAndAssets(Settings& settings) { | ||
if (!assets_dir_.is_valid()) { | ||
return; | ||
} | ||
|
||
settings.assets_dir = assets_dir_.get(); | ||
|
||
// In JIT execution, all snapshots are present within the binary itself and | ||
// don't need to be explicitly supplied by the embedder. In AOT, these | ||
// snapshots will be present in the application AOT dylib. | ||
if (DartVM::IsRunningPrecompiledCode()) { | ||
FML_CHECK(PrepareSettingsForAOTWithSymbols(settings, aot_symbols_)); | ||
} else { | ||
settings.application_kernels = [this]() { | ||
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings; | ||
kernel_mappings.emplace_back( | ||
fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin")); | ||
return kernel_mappings; | ||
}; | ||
} | ||
} | ||
|
||
} // namespace testing | ||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_TESTING_FIXTURE_TEST_H_ | ||
#define FLUTTER_TESTING_FIXTURE_TEST_H_ | ||
|
||
#include <memory> | ||
|
||
#include "flutter/common/settings.h" | ||
#include "flutter/runtime/dart_vm.h" | ||
#include "flutter/testing/elf_loader.h" | ||
#include "flutter/testing/test_dart_native_resolver.h" | ||
#include "flutter/testing/testing.h" | ||
#include "flutter/testing/thread_test.h" | ||
|
||
namespace flutter { | ||
namespace testing { | ||
|
||
class FixtureTest : public ThreadTest { | ||
public: | ||
FixtureTest(); | ||
|
||
Settings CreateSettingsForFixture(); | ||
|
||
private: | ||
std::shared_ptr<TestDartNativeResolver> native_resolver_; | ||
fml::UniqueFD assets_dir_; | ||
ELFAOTSymbols aot_symbols_; | ||
|
||
void SetSnapshotsAndAssets(Settings& settings); | ||
|
||
FML_DISALLOW_COPY_AND_ASSIGN(FixtureTest); | ||
}; | ||
|
||
} // namespace testing | ||
} // namespace flutter | ||
|
||
#endif // FLUTTER_TESTING_FIXTURE_TEST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters