@@ -1012,6 +1012,10 @@ class _ConstraintRenderBox extends RenderBox
1012
1012
final Map <ConstraintId , _ConstrainedNode > _tempConstrainedNodes = HashMap ();
1013
1013
late List <_ConstrainedNode > _paintingOrderList;
1014
1014
1015
+ static const int maxTimeUsage = 20 ;
1016
+ Queue <int > layoutTimeUsage = Queue ();
1017
+ Queue <int > paintTimeUsage = Queue ();
1018
+
1015
1019
set childConstraints (List <Constraint > value) {
1016
1020
bool isSameList = true ;
1017
1021
if (_childConstraints.length != value.length) {
@@ -1349,13 +1353,15 @@ class _ConstraintRenderBox extends RenderBox
1349
1353
_layoutByConstrainedNodeTrees (constrainedNodeTrees);
1350
1354
1351
1355
if (_releasePrintLayoutTime && kReleaseMode) {
1352
- print (
1353
- 'ConstraintLayout@${_debugName ?? hashCode } layout time = ${DateTime .now ().millisecondsSinceEpoch - startTime } ms(current is release mode).' );
1356
+ layoutTimeUsage.add (DateTime .now ().millisecondsSinceEpoch - startTime);
1357
+ if (layoutTimeUsage.length > maxTimeUsage) {
1358
+ layoutTimeUsage.removeFirst ();
1359
+ }
1354
1360
}
1355
1361
assert (() {
1356
- if (_debugPrintLayoutTime) {
1357
- debugPrint (
1358
- 'ConstraintLayout@${ _debugName ?? hashCode } layout time = ${ DateTime . now (). millisecondsSinceEpoch - startTime } ms(current is debug mode, release mode may take less time).' );
1362
+ layoutTimeUsage. add ( DateTime . now ().millisecondsSinceEpoch - startTime);
1363
+ if (layoutTimeUsage.length > maxTimeUsage) {
1364
+ layoutTimeUsage. removeFirst ( );
1359
1365
}
1360
1366
return true ;
1361
1367
}());
@@ -2000,17 +2006,69 @@ class _ConstraintRenderBox extends RenderBox
2000
2006
}());
2001
2007
2002
2008
if (_releasePrintLayoutTime && kReleaseMode) {
2003
- print (
2004
- 'ConstraintLayout@${_debugName ?? hashCode } paint time = ${DateTime .now ().millisecondsSinceEpoch - startTime } ms(current is release mode).' );
2009
+ paintTimeUsage.add (DateTime .now ().millisecondsSinceEpoch - startTime);
2010
+ if (paintTimeUsage.length > maxTimeUsage) {
2011
+ paintTimeUsage.removeFirst ();
2012
+ }
2013
+ _debugShowPerformance (context, offset);
2005
2014
}
2006
2015
assert (() {
2007
2016
if (_debugPrintLayoutTime) {
2008
- debugPrint (
2009
- 'ConstraintLayout@${_debugName ?? hashCode } paint time = ${DateTime .now ().millisecondsSinceEpoch - startTime } ms(current is debug mode, release mode may take less time).' );
2017
+ paintTimeUsage.add (DateTime .now ().millisecondsSinceEpoch - startTime);
2018
+ if (paintTimeUsage.length > maxTimeUsage) {
2019
+ paintTimeUsage.removeFirst ();
2020
+ }
2021
+ _debugShowPerformance (context, offset);
2010
2022
}
2011
2023
return true ;
2012
2024
}());
2013
2025
}
2026
+
2027
+ void _debugShowPerformance (
2028
+ PaintingContext context,
2029
+ Offset offset,
2030
+ ) {
2031
+ Iterator <int > layoutIterator = layoutTimeUsage.iterator;
2032
+ Iterator <int > paintIterator = paintTimeUsage.iterator;
2033
+ double heightOffset = 0 ;
2034
+ while (layoutIterator.moveNext () && paintIterator.moveNext ()) {
2035
+ int layoutTime = layoutIterator.current;
2036
+ int paintTime = paintIterator.current;
2037
+ ui.ParagraphBuilder paragraphBuilder =
2038
+ ui.ParagraphBuilder (ui.ParagraphStyle (
2039
+ textAlign: TextAlign .center,
2040
+ fontSize: 8 ,
2041
+ ));
2042
+ if (layoutTime > 5 || paintTime > 5 ) {
2043
+ paragraphBuilder.pushStyle (ui.TextStyle (
2044
+ color: Colors .red,
2045
+ ));
2046
+ } else {
2047
+ paragraphBuilder.pushStyle (ui.TextStyle (
2048
+ color: Colors .green,
2049
+ ));
2050
+ }
2051
+ paragraphBuilder.addText ("layout $layoutTime ms, draw $paintTime ms" );
2052
+ ui.Paragraph paragraph = paragraphBuilder.build ();
2053
+ paragraph.layout (const ui.ParagraphConstraints (
2054
+ width: 200 ,
2055
+ ));
2056
+ context.canvas.drawParagraph (paragraph, Offset (0 , heightOffset) + offset);
2057
+ heightOffset += 10 ;
2058
+ }
2059
+
2060
+ ui.ParagraphBuilder paragraphBuilder =
2061
+ ui.ParagraphBuilder (ui.ParagraphStyle (
2062
+ textAlign: TextAlign .center,
2063
+ fontSize: 8 ,
2064
+ ));
2065
+ paragraphBuilder.addText ('The bottom one is the latest' );
2066
+ ui.Paragraph paragraph = paragraphBuilder.build ();
2067
+ paragraph.layout (const ui.ParagraphConstraints (
2068
+ width: 200 ,
2069
+ ));
2070
+ context.canvas.drawParagraph (paragraph, Offset (0 , heightOffset) + offset);
2071
+ }
2014
2072
}
2015
2073
2016
2074
class _ConstrainedNode {
0 commit comments