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

Less allocations for node processing #6967

Merged
merged 8 commits into from
May 2, 2024
Merged

Less allocations for node processing #6967

merged 8 commits into from
May 2, 2024

Conversation

benaadams
Copy link
Member

@benaadams benaadams commented May 2, 2024

Changes

  • Introduce struct enumerators rather than using Linq

Addresses the following allocations
image

Types of changes

What types of changes does your code introduce?

  • Optimization

Testing

Requires testing

  • No

@benaadams benaadams requested review from asdacap and LukaszRozmej May 2, 2024 02:51
@benaadams benaadams requested a review from LukaszRozmej May 2, 2024 10:32
Comment on lines +136 to +143
if (count < _capacity / 2)
{
// Reduced to less than half of the capacity, resize the array.
T[] newArray = _arrayPool.Rent(count);
_array.AsSpan(0, count).CopyTo(newArray);
T[] oldArray = Interlocked.Exchange(ref _array, newArray);
_capacity = newArray.Length;
_arrayPool.Return(oldArray);
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth it, to potentially copy over this data to the new buffer?
I expect this data to be consumed fairly quickly and the whole buffer would return.

IMO probably not worth it at

Copy link
Member Author

Choose a reason for hiding this comment

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

The consumers only want 12 or 16 elements by default; so copy isn't that big, but can be hundreds or thousands of nodes

@benaadams benaadams merged commit abe8f8f into master May 2, 2024
67 checks passed
@benaadams benaadams deleted the nodes branch May 2, 2024 11:33
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.

2 participants