Skip to content

Commit

Permalink
Speedup Observatory elements first time rendering
Browse files Browse the repository at this point in the history
R=asiva@google.com, bkonyi@google.com

Review-Url: https://codereview.chromium.org/2995883002 .
  • Loading branch information
B3rn475 committed Aug 14, 2017
1 parent 2f5a59e commit 7568ed5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 17 additions & 3 deletions runtime/observatory/lib/src/elements/helpers/rendering_queue.dart
Expand Up @@ -56,15 +56,29 @@ class RenderingQueue {
/// Add a task to the queue.
/// If the current rendering phase is running it will be executed during this
/// rendering cycle, otherwise it will be queued for the next one.
void enqueue(RenderingTask r) {
void enqueue(RenderingTask r, {bool waitForBarrier: true}) {
assert(r != null);
// If no task are in the queue there is no rendering phase scheduled.
if (isEmpty) _render();
final wasEmpty = _queue.isEmpty;
_queue.addLast(r);
// If no task are in the queue there is no rendering phase scheduled.
if (wasEmpty) {
if (waitForBarrier) {
_render();
} else {
// We schedule the _renderLoop as a microtask to allow the
// scheduleRendering method to terminate, due to the fact that it is
// generally invoked from inside a HtmlElement.attached method
scheduleMicrotask(_renderLoop);
}
}
}

Future _render() async {
await _barrier.next;
_renderLoop();
}

void _renderLoop() {
while (_queue.isNotEmpty) {
_queue.first.render();
_queue.removeFirst();
Expand Down
Expand Up @@ -32,6 +32,7 @@ class RenderingScheduler<T extends Renderable> implements RenderingTask {
bool _dirty = false;
bool _renderingScheduled = false;
bool _notificationScheduled = false;
bool _waitForBarrier = false;

/// Element managed by this scheduler.
final T element;
Expand Down Expand Up @@ -103,7 +104,8 @@ class RenderingScheduler<T extends Renderable> implements RenderingTask {
void scheduleRendering() {
if (_renderingScheduled) return;
if (!_enabled) return;
queue.enqueue(this);
queue.enqueue(this, waitForBarrier: _waitForBarrier);
_waitForBarrier = true;
_renderingScheduled = true;
}

Expand Down

0 comments on commit 7568ed5

Please sign in to comment.