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

Sped up shader warmup by only drawing on a 100x100 surface #36482

Merged
merged 9 commits into from Jul 26, 2019

Conversation

@gaaclarke
Copy link
Contributor

gaaclarke commented Jul 18, 2019

Description

...and doing the draw calls on top of each other.

big.json.gz
little.json.gz

In big.json you'll see how the code was previous, and in little.json you'll see how it is after this PR. This saves about 14ms in readpixels.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • [x ] I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • [ x] I signed the CLA.
  • [ x] I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • [x ] I updated/added relevant documentation (doc comments with ///).
  • [x ] All existing and new tests are passing.
  • [x ] The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • [ x] I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • [ x] No, this is not a breaking change.
the draw calls on top of each other.
@fluttergithubbot

This comment has been minimized.

Copy link

fluttergithubbot commented Jul 18, 2019

It looks like this pull request may not have tests. Please make sure to add tests before merging. While there are exceptions to this rule, if this patch modifies code it is probably not an exception.

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

/cc @dnfield

@googlebot googlebot added the cla: yes label Jul 18, 2019
@gaaclarke gaaclarke requested a review from liyuqian Jul 18, 2019
@dnfield

This comment has been minimized.

Copy link
Member

dnfield commented Jul 18, 2019

Why not a 10x10 or a 1x1 surface instead?

Copy link
Contributor

liyuqian left a comment

Great! Can you please add some tests to:

  1. Verify the number of shaders being warmed up is as expected.
  2. Measure the total time of shader warm-up so we can track it in our dashboard (instead of doing an observatory tracing manually every time)
@@ -157,22 +155,18 @@ class DefaultShaderWarmUp extends ShaderWarmUp {
canvas.save();
for (ui.Paint paint in paints) {
canvas.drawPath(paths[i], paint);
canvas.translate(80.0, 0.0);

This comment has been minimized.

Copy link
@liyuqian

liyuqian Jul 18, 2019

Contributor

One reason that we added these 80.0 offsets is to visualize the warm up draws in examples/layers/raw/shader_warm_up.dart. Can you please add a flag here to preserve the offset in that debug app? (Maybe it's nice to do some refactor to force each draw within an 100x100 area, and automatically stack them together for actual warm-up and spread them for debugging.)

This comment has been minimized.

Copy link
@gaaclarke

gaaclarke Jul 18, 2019

Author Contributor

Done

This comment has been minimized.

Copy link
@liyuqian

liyuqian Jul 22, 2019

Contributor

Can you please also set the _drawCallSpacing to 80.0 in examples/layers/raw/shader_warm_up.dart?

This comment has been minimized.

Copy link
@liyuqian

liyuqian Jul 24, 2019

Contributor

@gaaclarke : any comment on this?

This comment has been minimized.

Copy link
@gaaclarke

gaaclarke Jul 24, 2019

Author Contributor

Done.

@gaaclarke

This comment has been minimized.

Copy link
Contributor Author

gaaclarke commented Jul 18, 2019

Why not a 10x10 or a 1x1 surface instead?

The draw calls have to be onscreen. We might be able to drop below 100x100 by tweaking the draw calls, but at 100x100 our read pixels is 4ms. I don't know if we'll be able to drop much below that. (Ideally we don't even read pixels but I've given up on that for now).

gaaclarke added 3 commits Jul 19, 2019
@liyuqian

This comment has been minimized.

Copy link
Contributor

liyuqian commented Jul 22, 2019

I realized that "adding a test to verify the number of shaders being warmed up is as expected" could be a little complicated, so I'm Ok to just have it manually checked for this PR, and maybe add it as a test in another dedicated PR.

On the other hand, add a test to measure the total time of shader warm-up so we can track it in our dashboard (instead of doing an observatory tracing manually every time) shouldn't be very difficult. For example, you can create MeasureDefaultShaderWarmUp that extends DefaultShaderWarmUp and overrides the execute like this:

class MeasureDefaultShaderWarmUp extends DefaultShaderWarmUp {
  Duration measuredTime;

  @override
  Future<void> execute() async {
    final DateTime start = DateTime.now();
    await super.execute();
    measuredTime = DateTime.now() - start;
  }
}

You can then write a device lab driver test to report the measurement: https://github.com/flutter/flutter/tree/master/dev/devicelab

Please let me know if you have any questions about the device lab test. Ideally, maybe we can land the driver test before the merge of this PR so we can get an official number of how much time is saved on our test devices 😄

@gaaclarke

This comment has been minimized.

Copy link
Contributor Author

gaaclarke commented Jul 24, 2019

You can then write a device lab driver test to report the measurement: https://github.com/flutter/flutter/tree/master/dev/devicelab

Hey Yuqian, I looked into this and it doesn't seem trivial. Whatever tests covered this code previously should cover this PR. I'm not sure if continual tracking of shader warmup is something we want to do, considering the effort to do so. This is demonstrably faster with profiling. I agree that the benchmark would be nice to have, but I'm failing to see how it is a good return on investment. Let's chat tomorrow.

Copy link
Contributor

liyuqian left a comment

LGTM modulo the analyze warnings.

@gaaclarke

This comment has been minimized.

Copy link
Contributor Author

gaaclarke commented Jul 26, 2019

The 2 outstanding tests have passed, they just aren't reporting so here for some reason.

@gaaclarke gaaclarke merged commit 9b150f1 into flutter:master Jul 26, 2019
73 of 75 checks passed
73 of 75 checks passed
customer_testing-windows
Details
release_smoke_tests
Details
tool_coverage-linux Task Summary
Details
WIP Ready for review
Details
add2app-macos Task Summary
Details
add2app-macos
Details
analyze Task Summary
Details
analyze
Details
build_tests-linux Task Summary
Details
build_tests-linux
Details
build_tests-macos Task Summary
Details
build_tests-macos
Details
build_tests-windows Task Summary
Details
build_tests-windows
Details
cla/google All necessary CLAs are signed
customer_testing-linux Task Summary
Details
customer_testing-linux
Details
customer_testing-macos Task Summary
Details
customer_testing-macos
Details
customer_testing-windows
Details
deploy_gallery Task Summary
Details
deploy_gallery
Details
deploy_gallery-macos Task Summary
Details
deploy_gallery-macos
Details
docs Task Summary
Details
docs
Details
flutter-build
Details
integration_tests-linux Task Summary
Details
integration_tests-linux
Details
integration_tests-macos Task Summary
Details
integration_tests-macos
Details
integration_tests-windows Task Summary
Details
integration_tests-windows
Details
integration_tests_gradle1-linux Task Summary
Details
integration_tests_gradle1-linux
Details
integration_tests_gradle2-linux Task Summary
Details
integration_tests_gradle2-linux
Details
release_smoke_tests
Details
tests_extras-linux Task Summary
Details
tests_extras-linux
Details
tests_extras-macos Task Summary
Details
tests_extras-macos
Details
tests_extras-windows Task Summary
Details
tests_extras-windows
Details
tests_framework_other-linux Task Summary
Details
tests_framework_other-linux
Details
tests_framework_other-macos Task Summary
Details
tests_framework_other-macos
Details
tests_framework_other-windows Task Summary
Details
tests_framework_other-windows
Details
tests_widgets-linux Task Summary
Details
tests_widgets-linux
Details
tests_widgets-macos Task Summary
Details
tests_widgets-macos
Details
tests_widgets-windows Task Summary
Details
tests_widgets-windows
Details
tool_coverage-linux
Details
tool_tests-linux Task Summary
Details
tool_tests-linux
Details
tool_tests-macos Task Summary
Details
tool_tests-macos
Details
tool_tests-windows Task Summary
Details
tool_tests-windows
Details
tool_tests_create-linux Task Summary
Details
tool_tests_create-linux
Details
tool_tests_create-macos Task Summary
Details
tool_tests_create-macos
Details
tool_tests_create-windows Task Summary
Details
tool_tests_create-windows
Details
tool_tests_integration-linux Task Summary
Details
tool_tests_integration-linux
Details
tool_tests_integration-macos Task Summary
Details
tool_tests_integration-macos
Details
tool_tests_integration-windows Task Summary
Details
tool_tests_integration-windows
Details
johnsonmh added a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
…6482)

Sped up shader warmup by only drawing on a 100x100 surface and doing
the draw calls on top of each other.
@flar

This comment has been minimized.

Copy link
Contributor

flar commented Sep 13, 2019

I'm investigating the historic slowdowns in the complex_layout_scroll_perf__memory benchmark. It looks like we were at around 5000 in late July and since then we've been stuck around 9000+.

It appears that this commit is responsible for that change. Here are 3 runs of the benchmark on a Moto G4 first running on commit 0d0af31 (which is just before this commit) and then on this commit 9b150f1

Stats for hash 0d0af3

On G4:

  "data": {
    "start-min": 34210,
    "start-max": 40838,
    "start-median": 39220,
    "end-min": 44052,
    "end-max": 46190,
    "end-median": 45034,
    "diff-min": 4464,
    "diff-max": 11980,
    "diff-median": 5033
  },
  "data": {
    "start-min": 35164,
    "start-max": 41233,
    "start-median": 40473,
    "end-min": 44973,
    "end-max": 45653,
    "end-median": 45321,
    "diff-min": 4125,
    "diff-max": 10322,
    "diff-median": 4487
  },
  "data": {
    "start-min": 32907,
    "start-max": 40356,
    "start-median": 39693,
    "end-min": 44393,
    "end-max": 48066,
    "end-median": 44879,
    "diff-min": 4099,
    "diff-max": 15159,
    "diff-median": 4907
  },

Stats for hash 9b150f:

On G4:

  "data": {
    "start-min": 31106,
    "start-max": 33471,
    "start-median": 31184,
    "end-min": 40494,
    "end-max": 45019,
    "end-median": 40980,
    "diff-min": 7793,
    "diff-max": 11548,
    "diff-median": 9319
  },
  "data": {
    "start-min": 31144,
    "start-max": 32886,
    "start-median": 31240,
    "end-min": 40506,
    "end-max": 41104,
    "end-median": 40906,
    "diff-min": 7932,
    "diff-max": 9798,
    "diff-median": 9690
  },
  "data": {
    "start-min": 30958,
    "start-max": 32838,
    "start-median": 31365,
    "end-min": 40332,
    "end-max": 41224,
    "end-median": 40892,
    "diff-min": 8054,
    "diff-max": 9874,
    "diff-median": 9501
  },
flar added a commit to flar/flutter that referenced this pull request Sep 13, 2019
@flar

This comment has been minimized.

Copy link
Contributor

flar commented Sep 13, 2019

See #40406

creativecreatorormaybenot added a commit to creativecreatorormaybenot/flutter that referenced this pull request Oct 31, 2019
…6482)

Sped up shader warmup by only drawing on a 100x100 surface and doing
the draw calls on top of each other.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.