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

Made flutter startup faster by allowing initialization to be parallelized #10182

Merged
merged 10 commits into from Sep 16, 2019

Conversation

@gaaclarke
Copy link
Contributor

gaaclarke commented Jul 26, 2019

I read through #8489 and tried to get the performance boost in a less invasive way.

We were serializing setup tasks for the shell that shouldn't need to be serialized. This PR lets them fly free as long as possible. It results in a 15% decrease in startup time (~0.05ms).

@gaaclarke gaaclarke requested review from chinmaygarde and liyuqian Sep 16, 2019
Copy link
Member

chinmaygarde left a comment

Very cool. A couple of nits but looks great.

fml::AutoResetWaitableEvent io_latch;
std::unique_ptr<ShellIOManager> io_manager;
std::promise<std::unique_ptr<ShellIOManager>> io_manager_promise;
auto io_manager = io_manager_promise.get_future();

This comment has been minimized.

Copy link
@chinmaygarde

chinmaygarde Sep 16, 2019

Member

Here and elsewhere, please append _future to the ivars or locals that are now futures.

This comment has been minimized.

Copy link
@gaaclarke

gaaclarke Sep 16, 2019

Author Contributor

done

on_create_rasterizer, //
shell = shell.get() //
]() {
TRACE_EVENT0("flutter", "ShellSetupGPUSubsystem");
if (auto new_rasterizer = on_create_rasterizer(*shell)) {
rasterizer = std::move(new_rasterizer);
rasterizer_promise.set_value(std::move(new_rasterizer));

This comment has been minimized.

Copy link
@chinmaygarde

chinmaygarde Sep 16, 2019

Member

This can just be condensed to one line now: rasterizer_promise.set_value(on_create_rasterizer(...))

This comment has been minimized.

Copy link
@gaaclarke

gaaclarke Sep 16, 2019

Author Contributor

done


// Create the rasterizer on the GPU thread.
fml::AutoResetWaitableEvent gpu_latch;
std::unique_ptr<Rasterizer> rasterizer;
std::promise<std::unique_ptr<Rasterizer>> rasterizer_promise;

This comment has been minimized.

Copy link
@chinmaygarde

chinmaygarde Sep 16, 2019

Member

Please move this before the platform view creation call. You don't have to wait for the platform view to be created before this can be kicked off as there is no dependency. This can be kicked off eagerly so that platform view creation can be concurrent with rasterizer creation as well.

This comment has been minimized.

Copy link
@gaaclarke

gaaclarke Sep 16, 2019

Author Contributor

done

Copy link
Contributor

liyuqian left a comment

Looks great! Do you have some numbers that quantify the improvements of this PR (by probably running some of our start up driver tests locally)? If we don't currently have benchmarks to cover this, we should add some :)

@chinmaygarde

This comment has been minimized.

Copy link
Member

chinmaygarde commented Sep 16, 2019

There is shell_benchmarks but those aren't wired up to any dashboard. There are already benchmarks for startup and shutdown that should show improvements after these changes.

@liyuqian

This comment has been minimized.

Copy link
Contributor

liyuqian commented Sep 16, 2019

Thanks @chinmaygarde ! @gaaclarke : can you please attach comparison numbers of the benchmarks that Chinmay mentioned in the PR description? (You can also find more "startup" tests in https://github.com/flutter/flutter/blob/master/dev/devicelab/manifest.yaml)

by reference and it was getted std::moved under the covers.
@gaaclarke

This comment has been minimized.

Copy link
Contributor Author

gaaclarke commented Sep 16, 2019

@liyuqian

=============== Before =========================
aaclarke-macbookpro2:src aaclarke$ ./out/host_profile/shell_benchmarks
Run on (12 X 2900 MHz CPU s)
2019-09-16 13:48:23
Benchmark                                  Time           CPU Iterations
------------------------------------------------------------------------
BM_ShellInitialization               2733011 ns     103132 ns       1000
BM_ShellShutdown                      718020 ns     281079 ns       2801
BM_ShellInitializationAndShutdown    3829377 ns     369490 ns       1000

=============== After =========================
aaclarke-macbookpro2:src aaclarke$ ./out/host_profile/shell_benchmarks
Run on (12 X 2900 MHz CPU s)
2019-09-16 13:49:41
Benchmark                                  Time           CPU Iterations
------------------------------------------------------------------------
BM_ShellInitialization               2677442 ns      98258 ns       1000
BM_ShellShutdown                      623944 ns     246920 ns       2861
BM_ShellInitializationAndShutdown    3286713 ns     313808 ns       1000

So 0.055569ms faster shell initialization?

@chinmaygarde

This comment has been minimized.

Copy link
Member

chinmaygarde commented Sep 16, 2019

~15% improvement? I'd ship it.

@chinmaygarde

This comment has been minimized.

Copy link
Member

chinmaygarde commented Sep 16, 2019

I think we should add tests that fully complete NotifyCreated on the platform view. That should give us a more usable number about startup costs.

Copy link
Contributor

liyuqian left a comment

Fantastic! Please remember to also put the numbers in the merge description so we can find it in git log. (By default, I think Github won't put your comment in the description.)

@gaaclarke gaaclarke merged commit 2620bab into flutter:master Sep 16, 2019
15 checks passed
15 checks passed
WIP Ready for review
Details
build_and_test_android_unopt_debug Task Summary
Details
build_and_test_android_unopt_debug
Details
build_and_test_linux_unopt_debug Task Summary
Details
build_and_test_linux_unopt_debug
Details
build_fuchsia_artifacts Task Summary
Details
build_fuchsia_artifacts
Details
build_windows_opt_debug Task Summary
Details
build_windows_opt_debug
Details
build_windows_unopt_debug Task Summary
Details
build_windows_unopt_debug
Details
cla/google All necessary CLAs are signed
format_and_dart_test Task Summary
Details
format_and_dart_test
Details
luci-engine
Details
@liyuqian

This comment has been minimized.

Copy link
Contributor

liyuqian commented Sep 17, 2019

@gaaclarke : I think @chinmaygarde 's ~15% calculation is based on BM_ShellInitializationAndShutdown, but your ~0.05ms seems to be based on BM_ShellInitialization... In your merged commit message (2620bab), however, they are described as the same thing...

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 17, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Sep 18, 2019
git@github.com:flutter/engine.git/compare/63873d9f421f...d1692d4cc703

git log 63873d9f421f..d1692d4cc703 --no-merges --oneline
2019-09-17 hterkelsen@users.noreply.github.com Update canvaskit backend (flutter/engine#12318)
2019-09-17 mouad.debbar@gmail.com README for the felt tool (flutter/engine#12323)
2019-09-17 jason-simmons@users.noreply.github.com Fix continuous event polling in the GLFW event loop (flutter/engine#12320)
2019-09-17 15365765+rafern@users.noreply.github.com Tests for #11283 (flutter/engine#12322)
2019-09-17 ditman@gmail.com Improve check to render (or not) a DRRect when inner falls outside of outer on RecordingCanvas (flutter/engine#12229)
2019-09-17 bkonyi@google.com Roll src/third_party/dart dd1969a43a..7505b3a5f0 (39 commits)
2019-09-17 30870216+gaaclarke@users.noreply.github.com Channel buffers (flutter/engine#12167)
2019-09-17 xster@google.com Make iOS FlutterViewController stop sending inactive/pause on app lifecycle events when not visible (flutter/engine#12128)
2019-09-17 stuartmorgan@google.com Adds PluginRegistry to the C++ client wrapper API (flutter/engine#12287)
2019-09-17 liyuqian@google.com Add "type" to getDisplayRefreshRate protocol (flutter/engine#12319)
2019-09-17 mouad.debbar@gmail.com Add a build command to felt (flutter/engine#12303)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia df432d5efb70..d545bfbb94ca (1 commits) (flutter/engine#12316)
2019-09-17 skia-flutter-autoroll@skia.org Roll fuchsia/sdk/core/linux-amd64 from rwf0-... to RRgw-... (flutter/engine#12315)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia f8486f2c5fb6..df432d5efb70 (1 commits) (flutter/engine#12313)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia b47704b0bd34..f8486f2c5fb6 (2 commits) (flutter/engine#12312)
2019-09-16 jason-simmons@users.noreply.github.com Fix the declaration of setSystemGestureExclusionRects to match the PlatformMessageHandler interface (flutter/engine#12306)
2019-09-16 gw280@google.com Manage resource and onscreen contexts using separate IOSGLContext objects (flutter/engine#12277)
2019-09-16 goderbauer@google.com Cleanup in web_ui (flutter/engine#12307)
2019-09-16 30870216+gaaclarke@users.noreply.github.com Made flutter startup faster by allowing initialization to be parallelized (flutter/engine#10182)
2019-09-16 skia-flutter-autoroll@skia.org Roll src/third_party/skia c22498502cda..b47704b0bd34 (16 commits) (flutter/engine#12304)
2019-09-16 jonahwilliams@google.com Include firefox in check to quote font families (flutter/engine#12288)
2019-09-16 bkonyi@google.com Roll src/third_party/dart 7799f424f4..dd1969a43a (2 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Inconnu08 added a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
git@github.com:flutter/engine.git/compare/63873d9f421f...d1692d4cc703

git log 63873d9f421f..d1692d4cc703 --no-merges --oneline
2019-09-17 hterkelsen@users.noreply.github.com Update canvaskit backend (flutter/engine#12318)
2019-09-17 mouad.debbar@gmail.com README for the felt tool (flutter/engine#12323)
2019-09-17 jason-simmons@users.noreply.github.com Fix continuous event polling in the GLFW event loop (flutter/engine#12320)
2019-09-17 15365765+rafern@users.noreply.github.com Tests for flutter#11283 (flutter/engine#12322)
2019-09-17 ditman@gmail.com Improve check to render (or not) a DRRect when inner falls outside of outer on RecordingCanvas (flutter/engine#12229)
2019-09-17 bkonyi@google.com Roll src/third_party/dart dd1969a43a..7505b3a5f0 (39 commits)
2019-09-17 30870216+gaaclarke@users.noreply.github.com Channel buffers (flutter/engine#12167)
2019-09-17 xster@google.com Make iOS FlutterViewController stop sending inactive/pause on app lifecycle events when not visible (flutter/engine#12128)
2019-09-17 stuartmorgan@google.com Adds PluginRegistry to the C++ client wrapper API (flutter/engine#12287)
2019-09-17 liyuqian@google.com Add "type" to getDisplayRefreshRate protocol (flutter/engine#12319)
2019-09-17 mouad.debbar@gmail.com Add a build command to felt (flutter/engine#12303)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia df432d5efb70..d545bfbb94ca (1 commits) (flutter/engine#12316)
2019-09-17 skia-flutter-autoroll@skia.org Roll fuchsia/sdk/core/linux-amd64 from rwf0-... to RRgw-... (flutter/engine#12315)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia f8486f2c5fb6..df432d5efb70 (1 commits) (flutter/engine#12313)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia b47704b0bd34..f8486f2c5fb6 (2 commits) (flutter/engine#12312)
2019-09-16 jason-simmons@users.noreply.github.com Fix the declaration of setSystemGestureExclusionRects to match the PlatformMessageHandler interface (flutter/engine#12306)
2019-09-16 gw280@google.com Manage resource and onscreen contexts using separate IOSGLContext objects (flutter/engine#12277)
2019-09-16 goderbauer@google.com Cleanup in web_ui (flutter/engine#12307)
2019-09-16 30870216+gaaclarke@users.noreply.github.com Made flutter startup faster by allowing initialization to be parallelized (flutter/engine#10182)
2019-09-16 skia-flutter-autoroll@skia.org Roll src/third_party/skia c22498502cda..b47704b0bd34 (16 commits) (flutter/engine#12304)
2019-09-16 jonahwilliams@google.com Include firefox in check to quote font families (flutter/engine#12288)
2019-09-16 bkonyi@google.com Roll src/third_party/dart 7799f424f4..dd1969a43a (2 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
creativecreatorormaybenot added a commit to creativecreatorormaybenot/flutter that referenced this pull request Oct 31, 2019
git@github.com:flutter/engine.git/compare/63873d9f421f...d1692d4

git log 63873d9..d1692d4 --no-merges --oneline
2019-09-17 hterkelsen@users.noreply.github.com Update canvaskit backend (flutter/engine#12318)
2019-09-17 mouad.debbar@gmail.com README for the felt tool (flutter/engine#12323)
2019-09-17 jason-simmons@users.noreply.github.com Fix continuous event polling in the GLFW event loop (flutter/engine#12320)
2019-09-17 15365765+rafern@users.noreply.github.com Tests for flutter#11283 (flutter/engine#12322)
2019-09-17 ditman@gmail.com Improve check to render (or not) a DRRect when inner falls outside of outer on RecordingCanvas (flutter/engine#12229)
2019-09-17 bkonyi@google.com Roll src/third_party/dart dd1969a43a..7505b3a5f0 (39 commits)
2019-09-17 30870216+gaaclarke@users.noreply.github.com Channel buffers (flutter/engine#12167)
2019-09-17 xster@google.com Make iOS FlutterViewController stop sending inactive/pause on app lifecycle events when not visible (flutter/engine#12128)
2019-09-17 stuartmorgan@google.com Adds PluginRegistry to the C++ client wrapper API (flutter/engine#12287)
2019-09-17 liyuqian@google.com Add "type" to getDisplayRefreshRate protocol (flutter/engine#12319)
2019-09-17 mouad.debbar@gmail.com Add a build command to felt (flutter/engine#12303)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia df432d5efb70..d545bfbb94ca (1 commits) (flutter/engine#12316)
2019-09-17 skia-flutter-autoroll@skia.org Roll fuchsia/sdk/core/linux-amd64 from rwf0-... to RRgw-... (flutter/engine#12315)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia f8486f2c5fb6..df432d5efb70 (1 commits) (flutter/engine#12313)
2019-09-17 skia-flutter-autoroll@skia.org Roll src/third_party/skia b47704b0bd34..f8486f2c5fb6 (2 commits) (flutter/engine#12312)
2019-09-16 jason-simmons@users.noreply.github.com Fix the declaration of setSystemGestureExclusionRects to match the PlatformMessageHandler interface (flutter/engine#12306)
2019-09-16 gw280@google.com Manage resource and onscreen contexts using separate IOSGLContext objects (flutter/engine#12277)
2019-09-16 goderbauer@google.com Cleanup in web_ui (flutter/engine#12307)
2019-09-16 30870216+gaaclarke@users.noreply.github.com Made flutter startup faster by allowing initialization to be parallelized (flutter/engine#10182)
2019-09-16 skia-flutter-autoroll@skia.org Roll src/third_party/skia c22498502cda..b47704b0bd34 (16 commits) (flutter/engine#12304)
2019-09-16 jonahwilliams@google.com Include firefox in check to quote font families (flutter/engine#12288)
2019-09-16 bkonyi@google.com Roll src/third_party/dart 7799f424f4..dd1969a43a (2 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.