From 7937b1d51f7b2bc835845f0c2fdbea15013251ec Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 17 Jul 2023 10:34:35 -0700 Subject: [PATCH] Skip the iteration in Layer._fireCompositionCallbacks if the callbacks map is empty (#130438) This was showing up as a hot spot in some benchmarks and profiles. This function is called frequently during frame builds and often has an empty map. There may be significant overhead from obtaining the values iterator and cloning it into a list. See https://github.com/flutter/flutter/issues/130339 --- packages/flutter/lib/src/rendering/layer.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/flutter/lib/src/rendering/layer.dart b/packages/flutter/lib/src/rendering/layer.dart index 779574f3f8..51b5e86a2e 100644 --- a/packages/flutter/lib/src/rendering/layer.dart +++ b/packages/flutter/lib/src/rendering/layer.dart @@ -172,6 +172,9 @@ abstract class Layer with DiagnosticableTreeMixin { } void _fireCompositionCallbacks({required bool includeChildren}) { + if (_callbacks.isEmpty) { + return; + } for (final VoidCallback callback in List.of(_callbacks.values)) { callback(); }