这是indexloc提供的服务,不要输入任何密码
Skip to content

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

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

Merged
merged 9 commits into from
Jul 26, 2019

Conversation

gaaclarke
Copy link
Member

@gaaclarke 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.

@fluttergithubbot
Copy link
Contributor

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

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 18, 2019
@gaaclarke gaaclarke requested a review from liyuqian July 18, 2019 19:57
@dnfield
Copy link
Contributor

dnfield commented Jul 18, 2019

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

Copy link
Contributor

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

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

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

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.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@gaaclarke : any comment on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@gaaclarke
Copy link
Member Author

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).

@liyuqian
Copy link
Contributor

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
Copy link
Member Author

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 liyuqian left a comment

Choose a reason for hiding this comment

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

LGTM modulo the analyze warnings.

@gaaclarke
Copy link
Member Author

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
johnsonmh pushed 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
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
Copy link
Contributor

flar commented Sep 13, 2019

See #40406

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants