Skip to content

More efficient collect by time/scheduler? #127

Open
@jessegrosjean

Description

@jessegrosjean

Thanks for CombineExt, I've been using in my apps for a long time.

I recently ran into a performance issue with "Combine" .collect(.byTime). It starts a repeating timer that runs for the entire duration of the subscription. Depending on the time stride and how many of these you have it can really effect performance even when no items are getting published.

The problem that I was trying to solve with .collect(.byTime) is:

  1. You have background work being performed and generating a sequence of results.
  2. You have a UI that you want to update with those results (you want them all, not just last/first)
  3. You want to batch process the results, it's too expensive to schedule each result separately on the main queue.
  4. You only want to schedule a timer when items are passing through the publisher, don't want a repeating timer

If there's a good Combine or CombineExt way to do this I would love to know. Otherwise I have a publisher that does what I need here. The timing logic is quite simple, though I don't really understand the details of the surrounding "Combine" logic. It's mostly copied/pasted from CombineX.

https://forums.swift.org/t/combines-collect-bytime-schedules-a-repeating-timer/57456

Assuming this type of scheduler doesn't already existing I think the basic logic would be a good addition to CombineExt, though probably someone more in tune with combine internals should check and adapt the code to CombineExt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions