Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOf replaced by Count at Add method - Performance issue #975 fixed #1096

Merged
merged 2 commits into from
Nov 30, 2022

Conversation

maije
Copy link
Contributor

@maije maije commented Nov 29, 2022

No need to calculate the index of a new object in the collection if the position is always the (Count-1) after the addition.
The Add method at TableRowCollection is being called billions (US) of times for tens of thousands of prints.
Comparative metrics regarding this issue can be found at #975

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
@dnfadmin
Copy link

dnfadmin commented Nov 29, 2022

CLA assistant check
All CLA requirements met.

@maije maije changed the title Performance issue #975 fixed IndexOf replaced by Count at Add method - Performance issue #975 fixed Nov 29, 2022
Copy link
Contributor

@patriksvensson patriksvensson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@patriksvensson patriksvensson merged commit 4258cbf into spectreconsole:main Nov 30, 2022
@patriksvensson
Copy link
Contributor

Merged! Thank you for your contribution. Much appreciated! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants