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

Avoid some List allocations and resizes #857

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

Conversation

Henr1k80
Copy link

@Henr1k80 Henr1k80 commented Aug 1, 2024

Q A
Bug fix? no, performance improvement
New feature? no
BC breaks? no
Related Issue no
Need Doc update no

Describe your change

Profiling my application, SplitIntoBatchesAsync showed up and I spotted room for improvement.

SplitIntoBatchesAsync
Before, a new List was allocated and data copied, even though batch size is below max.

If we can get the size of the batch and it is below max batch size, no new allocations & copying happens and the data is used directly.

If the batch size is over max batch size, resizing the records list from 4->8->16->32->64->128->256->512->1024 is avoided.
Resizing the list involves allocating new arrays for the mentioned capacities and copying the data over.
Instead one array of max batch size is allocated.
If batch size % max batch size != 0 an array is allocated for the last batch.

BatchRequest
If we can get the size of the data, the Operations List is initiated with the size, so resizing it from 4->8->16->32->64->128->256->512->1024 for max batch size is avoided.

What problem is this fixing?

This will avoid allocations & resizing of records for batches smaller than max batch size for all collections.

Resizing lists will be avoided for SplitIntoBatchesAsync & BatchRequest for all collections of batches & data.

This will reduce resources spent on allocating, resizing, memory pressure & garbage collection for these operations.
Thereby increasing the perceived performance of algolia.
And lowering the environmental footprint of users of this SDK

@Henr1k80 Henr1k80 requested a review from sbellone as a code owner August 1, 2024 13:34
@sbellone sbellone requested a review from morganleroi August 6, 2024 10:38
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