viceroypenguin / SuperLinq

Extensions to LINQ to Objects
Apache License 2.0
115 stars 12 forks source link

Async version of `Batch` reuses same array for each batch #651

Closed danielearwicker closed 5 months ago

danielearwicker commented 5 months ago

The sync version of Batch has two versions, one that allocates a fresh array per batch, and the other which reuses the same array.

The reusing approach breaks easily due to the lazy nature of sequences, and so can only be used with care.

The async version of Batch only has one implementation, that reuses the array. The user has to follow it with .Select(x => x.ToList()) thus wasting time on an extra copy per batch.

viceroypenguin commented 5 months ago

The async version is a bug, I agree. Addressed in #652. I'll do a 6.0.1 release later this week.

The reusing approach breaks easily due to the lazy nature of sequences, and so can only be used with care.

I agree; which is why it is not the default for the sync version. However, it is a reduced-allocation method, for those that desire to operate in that path. I fully expect any consumers who choose to do so are aware of the potential consequences; and why that version of the operator does not return the array by default, but uses a transform method to encourage transforming the array to something else to be returned.

danielearwicker commented 5 months ago

Awesome, look forward to the update. This is an excellent package.