Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: runtime/observatory/lib/src/elements/helpers/rendering_queue.dart

Issue 2995883002: Speedup Observatory elements first time rendering (Closed)
Patch Set: Fix task queueing Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:html'; 5 import 'dart:html';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 /// A generic rendering task that can be scheduled. 9 /// A generic rendering task that can be scheduled.
10 abstract class RenderingTask { 10 abstract class RenderingTask {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier()); 49 RenderingQueue() : this.fromBarrier(new NextAnimationFrameBarrier());
50 50
51 /// Creates a RenderingQueue with a custom synchronization barrier. 51 /// Creates a RenderingQueue with a custom synchronization barrier.
52 RenderingQueue.fromBarrier(this._barrier) { 52 RenderingQueue.fromBarrier(this._barrier) {
53 assert(this._barrier != null); 53 assert(this._barrier != null);
54 } 54 }
55 55
56 /// Add a task to the queue. 56 /// Add a task to the queue.
57 /// If the current rendering phase is running it will be executed during this 57 /// If the current rendering phase is running it will be executed during this
58 /// rendering cycle, otherwise it will be queued for the next one. 58 /// rendering cycle, otherwise it will be queued for the next one.
59 void enqueue(RenderingTask r) { 59 void enqueue(RenderingTask r, {bool realtime: false}) {
siva 2017/08/14 22:35:01 why not rename realtime to waitForBarrier to make
cbernaschina 2017/08/14 23:04:14 Done.
60 assert(r != null); 60 assert(r != null);
61 final wasEmpty = _queue.isEmpty;
62 _queue.addLast(r);
61 // If no task are in the queue there is no rendering phase scheduled. 63 // If no task are in the queue there is no rendering phase scheduled.
62 if (isEmpty) _render(); 64 if (wasEmpty) {
63 _queue.addLast(r); 65 if (realtime) {
66 // If it is a realtime request avoid to wait for the barrier
67 scheduleMicrotask(_renderLoop);
68 } else {
69 _render();
70 }
71 }
64 } 72 }
65 73
66 Future _render() async { 74 Future _render() async {
67 await _barrier.next; 75 await _barrier.next;
76 _renderLoop();
77 }
78
79 void _renderLoop() {
68 while (_queue.isNotEmpty) { 80 while (_queue.isNotEmpty) {
69 _queue.first.render(); 81 _queue.first.render();
70 _queue.removeFirst(); 82 _queue.removeFirst();
71 } 83 }
72 } 84 }
73 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698