Skip to content

Commit

Permalink
Performance issue solved
Browse files Browse the repository at this point in the history
When printing tens of thousands of lines, there is a performance issue. The TableRowCollection -> Add method was being called millions of times.
Once  it is called, it returns the index  of the added element.
As the element is added to a List (new List<TableRow>, I believe it is not needed to use IndexOf because it will be added always at the last position.
Replacing the IndexOf call by a Count - 1 improves the performance in this scenario.
Related issue: spectreconsole#975
  • Loading branch information
maije2 committed Nov 29, 2022
1 parent a755cc5 commit c502d9e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Spectre.Console/Widgets/Table/TableRowCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int Add(IEnumerable<IRenderable> columns)
{
var row = CreateRow(columns);
_list.Add(row);
return _list.IndexOf(row);
return _list.Count - 1;
}
}

Expand Down

0 comments on commit c502d9e

Please sign in to comment.