Skip to content

Skip LayerTree::Preroll LayerTree::Paint & Swapbuffer when frame_damage is empty #101097

@linxuebin1990

Description

@linxuebin1990

Use case

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      title: "demo",
      theme: CupertinoThemeData(),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const CupertinoPageScaffold(
      backgroundColor: Colors.white70,
      child: Padding(
        padding: EdgeInsets.only(top: 100, left: 15, right: 15),
        child: CupertinoTextField(
          placeholder: "iOS-style text field",
        ),
      ),
    );
  }
}

A simple Demo for TextField, the screenShot is as follows:
screen (1)

Proposal

Add Log in DiffContext::ComputeDamage https://github.com/flutter/engine/blob/main/flow/diff_context.cc#L70, we can see log as fellow:

E/flutter (17227): [ERROR:flutter/flow/diff_context.cc(94)] frame_damage: width = 6 height = 48
E/flutter (17227): [ERROR:flutter/flow/diff_context.cc(93)] buffer_damage: width = 6 height = 48
E/flutter (17227): [ERROR:flutter/flow/diff_context.cc(94)] frame_damage: width = 6 height = 48
E/flutter (17227): [ERROR:flutter/flow/diff_context.cc(93)] buffer_damage: width = 6 height = 48
E/flutter (17227): [ERROR:flutter/flow/diff_context.cc(94)] frame_damage: width = 6 height = 48
E/flutter (17227): [ERROR:flutter/flow/diff_context.cc(93)] buffer_damage: width = 6 height = 48
E/flutter (17227): [ERROR:flutter/flow/diff_context.cc(94)] frame_damage: width = 0 height = 0

From the logs above we can see that sometimes the frame_damage is empty.
So, there is no difference between the current frame and the previous frame.
Then can we discard the subsequent processes of the current frame, such as layertree's preroll, layertree's paint, and so on?
When we discard the empty frame_damge, we can get the trace below:

image
(left is empty frame_damage, right is not.)

Can reduce 6 ms cpu time on my phone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions