Skip to content

Commit b1fae1b

Browse files
committed
content: Use "growable: false" optimization in _buildInlineList
Making lists non-growable is a small optimization that's particularly helpful when creating a large number of short lists. That describes what we do here, mapping inline content nodes to corresponding inline spans: there will be tons of these nodes in a message list; tons of them will be in lists of one element (like any paragraph of plain text, or any link or strong/bold or emphasis/italic span with no further markup inside it); and probably the bulk of the rest will be in lists of two or three. So this is a spot where the optimization may well have a material performance impact. In any case it's essentially free; since we didn't want to add or remove elements anyway, the only cost is the extra few tokens in the source code.
1 parent 54e036a commit b1fae1b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/widgets/content.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class _SingleChildScrollViewWithScrollbarState
298298
//
299299

300300
List<InlineSpan> _buildInlineList(List<InlineContentNode> nodes) =>
301-
List.of(nodes.map(_buildInlineNode));
301+
nodes.map(_buildInlineNode).toList(growable: false);
302302

303303
InlineSpan _buildInlineNode(InlineContentNode node) {
304304
InlineSpan styled(List<InlineContentNode> nodes, TextStyle style) =>

0 commit comments

Comments
 (0)