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

[7.x] Make LazyCollection#countBy be lazy #33801

Merged
merged 2 commits into from
Aug 10, 2020

Conversation

JosephSilber
Copy link
Contributor

The collection's current countBy implementation uses groupBy.

groupBy is inherently not lazy (being a form of bucket sort). This means that in order to count occurrences, we need to pull the whole dataset into memory at once.

We can do better.

The code in this PR only pulls a single item at a time, and increases the counter. The actual item is then promptly discarded, so that we never keep more than a single item in memory.

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