Skip to content

Remove AsyncIterator: Sendable requirement from debounce #197

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

Closed
wants to merge 1 commit into from

Conversation

FranzBusch
Copy link
Member

Motivation

The current implementation of AsyncDebounceSequence requires the base AsyncIterator to be Sendable. This is causing two problems:

  1. It only allows users to use debounce if their AsyncSequence.AsyncIterator is Sendable
  2. In debounce we are creating a lot of new Tasks and reating Tasks is not cheap.

My main goal of this PR was to remove the Sendable constraint from debounce.

Modification

This PR overhauls the implementation of debounce and aligns it with the implementation of the open merge PR #185 . The most important changes are this:

  • I removed the Sendable requirement from the base sequences AsyncIterator.
  • Instead of creating new Tasks for the sleep and for the upstream consumption. I am now creating one Task and manipulate it by signalling continuations
  • I am not cancelling the sleep. Instead I am recalculating the time left to sleep when a sleep finishes.

Result

In the end, this PR swaps the implementation of AsyncDebounceSequence and drops the Sendable constraint and passes all tests. Furthermore, on my local performance testing I saw up 150% speed increase in throughput.

# Motivation
The current implementation of `AsyncDebounceSequence` requires the base `AsyncIterator` to be `Sendable`. This is causing two problems:

1. It only allows users to use `debounce` if their `AsyncSequence.AsyncIterator` is `Sendable`
2. In `debounce` we are creating a lot of new `Task`s and reating `Task`s is not cheap.

My main goal of this PR was to remove the `Sendable` constraint from `debounce`.

# Modification
This PR overhauls the implementation of `debounce` and aligns it with the implementation of the open `merge` PR apple#185 . The most important changes are this:
- I removed the `Sendable` requirement from the base sequences `AsyncIterator`.
- Instead of creating new Tasks for the sleep and for the upstream consumption. I am now creating one Task and manipulate it by signalling continuations
- I am not cancelling the sleep. Instead I am recalculating the time left to sleep when a sleep finishes.

# Result
In the end, this PR swaps the implementation of `AsyncDebounceSequence` and drops the `Sendable` constraint and passes all tests. Furthermore, on my local performance testing I saw up 150% speed increase in throughput.
@FranzBusch FranzBusch closed this Sep 11, 2022
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