apple / apple/swift-async-algorithms
Improve implementation of `merge`
- Dominant language
- Swift
- Stars
- 3.7k
- Forks
- 226
- Avg merge
- 10d 3h
- Merged PRs (30d)
- 1
Description
`merge` currently allocates more than it should on `next` calls, by creating new arrays with no pre-reserved capacity. What’s more, in its current form of allowing max 3 streams to be merged, this array could actually just be a tuple and avoid the allocation altogether.
There are comments throughout the implementation that suggest the idea was to eventually use variadic generics to merge N streams. We should decide if this is something we actually want to do, and either reserve enough capacity in the `continuations` array to avoid the constant resizing, or stick to a tuple if we won’t allow more than 3 (or some other fixed number of) streams.
Contributor guide
Research direction
Start by locating the merge implementation and its next calls, then inspect how the continuations array is created and resized. Decide whether merge should support more than three streams; done means either reserving appropriate capacity or replacing the array with a tuple for the supported fixed arity, with allocation behavior covered by the existing tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100