Skip to content

Use custom collector to avoid intermediate array allocations #2168

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgravell
Copy link
Member

Context #2166

List<T> uses initial-size plus doubling, which means that for large result sets you can get multiple arrays, for example for 90 rows you might have arrays with sizes 16, 32, 64, and 128 for 90, with the final result list using the oversized 128-element array, with 90 elements.

This change uses a custom collector for this part - same logic, but it uses the array-pool so that those intermediate arrays are recycled, and the final array is right-sized, i.e. a list with count 90 and capacity 90, and all intermediate arrays reused.

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.

1 participant