Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f167c43

Browse files
committed
Move build() off microtasks
Rather than using a microtask to schedule component build functions, instead use the scheduler. We now tread building just like layout and painting as a visual update.
1 parent f92e594 commit f167c43

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

sky/packages/sky/lib/rendering/sky_binding.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SkyBinding {
4747
_renderView = renderViewOverride;
4848
}
4949
assert(_renderView != null);
50-
scheduler.addPersistentFrameCallback(_beginFrame);
50+
scheduler.addPersistentFrameCallback(beginFrame);
5151

5252
assert(_instance == this);
5353
}
@@ -69,7 +69,7 @@ class SkyBinding {
6969
void set root(RenderBox value) {
7070
_renderView.child = value;
7171
}
72-
void _beginFrame(double timeStamp) {
72+
void beginFrame(double timeStamp) {
7373
RenderObject.flushLayout();
7474
RenderObject.flushPaint();
7575
_renderView.paintFrame();

sky/packages/sky/lib/widgets/widget.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:collection';
77
import 'dart:sky' as sky;
88

99
import 'package:sky/base/hit_test.dart';
10+
import 'package:sky/base/scheduler.dart' as scheduler;
1011
import 'package:sky/mojo/activity.dart' as activity;
1112
import 'package:sky/rendering/box.dart';
1213
import 'package:sky/rendering/object.dart';
@@ -651,6 +652,11 @@ abstract class Component extends Widget {
651652
_scheduleComponentForRender(this);
652653
}
653654

655+
static void flushBuild() {
656+
if (!_dirtyComponents.isEmpty)
657+
_buildDirtyComponents();
658+
}
659+
654660
Widget build();
655661

656662
}
@@ -759,13 +765,15 @@ void _absorbDirtyComponents(List<Component> list) {
759765
}
760766

761767
void _buildDirtyComponents() {
768+
assert(!_dirtyComponents.isEmpty);
769+
762770
Stopwatch sw;
763771
if (_shouldLogRenderDuration)
764772
sw = new Stopwatch()..start();
765773

766774
_inRenderDirtyComponents = true;
767775
try {
768-
sky.tracing.begin('Widgets._buildDirtyComponents');
776+
sky.tracing.begin('Component.flushBuild');
769777
List<Component> sortedDirtyComponents = new List<Component>();
770778
_absorbDirtyComponents(sortedDirtyComponents);
771779
int index = 0;
@@ -784,7 +792,7 @@ void _buildDirtyComponents() {
784792
} finally {
785793
_buildScheduled = false;
786794
_inRenderDirtyComponents = false;
787-
sky.tracing.end('Widgets._buildDirtyComponents');
795+
sky.tracing.end('Component.flushBuild');
788796
}
789797

790798
Widget._notifyMountStatusChanged();
@@ -795,21 +803,20 @@ void _buildDirtyComponents() {
795803
if (_debugFrameTimes.length >= 1000) {
796804
_debugFrameTimes.sort();
797805
const int i = 99;
798-
print('_buildDirtyComponents: ${i+1}th fastest frame out of the last ${_debugFrameTimes.length}: ${_debugFrameTimes[i]} microseconds');
806+
print('Component.flushBuild: ${i+1}th fastest frame out of the last ${_debugFrameTimes.length}: ${_debugFrameTimes[i]} microseconds');
799807
_debugFrameTimes.clear();
800808
}
801809
}
802810
}
803811

804-
void _scheduleComponentForRender(Component c) {
805-
_dirtyComponents.add(c);
812+
void _scheduleComponentForRender(Component component) {
813+
_dirtyComponents.add(component);
806814
if (!_buildScheduled) {
807815
_buildScheduled = true;
808-
new Future.microtask(_buildDirtyComponents);
816+
scheduler.ensureVisualUpdate();
809817
}
810818
}
811819

812-
813820
// RenderObjectWrappers correspond to a desired state of a RenderObject.
814821
// They are fully immutable, with one exception: A Widget which is a
815822
// Component which lives within an MultiChildRenderObjectWrapper's
@@ -1178,6 +1185,11 @@ class WidgetSkyBinding extends SkyBinding {
11781185
}
11791186
}
11801187

1188+
void beginFrame(double timeStamp) {
1189+
Component.flushBuild();
1190+
super.beginFrame(timeStamp);
1191+
}
1192+
11811193
}
11821194

11831195
abstract class App extends StatefulComponent {

sky/tests/resources/display_list.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class TestRenderView extends RenderView {
149149
// TEST API:
150150

151151
void syncCheckFrame() {
152+
Component.flushBuild();
152153
RenderObject.flushLayout();
153154
paintFrame();
154155
print(lastPaint); // TODO(ianh): figure out how to make this fit the unit testing framework better

0 commit comments

Comments
 (0)