From 1f77a79a2c51ef36ce8bb439dc980764742e8932 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 5 Mar 2015 11:38:17 -0800 Subject: [PATCH] fn.dart shouldn't spam the log This CL introduces a flag to control whether fn.dart prints the render duration to the console. By default, the flag is off to avoid log spam. Also, improve the way we intialize _isInCheckedMode to make use of the fact that Dart intializes final fields lazily. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/982073002 --- framework/fn.dart | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/framework/fn.dart b/framework/fn.dart index cfd25775265..27b44b2c595 100644 --- a/framework/fn.dart +++ b/framework/fn.dart @@ -9,23 +9,19 @@ import 'dart:collection'; import 'dart:sky' as sky; import 'reflect.dart' as reflect; -bool _checkedMode; - -bool _debugWarnings() { +bool _initIsInCheckedMode() { void testFn(double i) {} - - if (_checkedMode == null) { - _checkedMode = false; - try { - testFn('not a double'); - } catch (ex) { - _checkedMode = true; - } + try { + testFn('not a double'); + } catch (ex) { + return true; } - - return _checkedMode; + return false; } +final bool _isInCheckedMode = _initIsInCheckedMode(); +final bool _shouldLogRenderDuration = false; + class EventHandler { final String type; final sky.EventListener listener; @@ -152,7 +148,7 @@ abstract class Element extends Node { _className = style == null ? '': style._className; _children = children == null ? _emptyList : children; - if (_debugWarnings()) { + if (_isInCheckedMode) { _debugReportDuplicateIds(); } } @@ -516,8 +512,10 @@ void _renderDirtyComponents() { _dirtyComponents.clear(); _renderScheduled = false; + sw.stop(); - print("Render took ${sw.elapsedMicroseconds} microseconds"); + if (_shouldLogRenderDuration) + print("Render took ${sw.elapsedMicroseconds} microseconds"); } void _scheduleComponentForRender(Component c) { @@ -646,18 +644,19 @@ abstract class Component extends Node { abstract class App extends Component { sky.Node _host = null; - App() - : super(stateful: true) { - + App() : super(stateful: true) { _host = sky.document.createElement('div'); sky.document.appendChild(_host); new Future.microtask(() { Stopwatch sw = new Stopwatch()..start(); + _sync(null, _host, null); assert(_root is sky.Node); + sw.stop(); - print("Initial render: ${sw.elapsedMicroseconds} microseconds"); + if (_shouldLogRenderDuration) + print("Initial render: ${sw.elapsedMicroseconds} microseconds"); }); } }