Automattic / Automattic-Tracks-iOS

Client library for tracking user events for later analysis
GNU General Public License v2.0
43 stars 12 forks source link

Send tracks events in batches of no more than 1000 #293

Closed bjhomer closed 3 months ago

bjhomer commented 4 months ago

When sending tracks events, adds a limit of 1000 events to send per batch.

There are two reasons for this:

With these changes, the UI is much less likely to hang. On my device, fetching a batch of 1000 events took only 0.03s, which is probably acceptable on the main thread. By contrast, fetching 93,000 events took 2.25s, a clearly noticeable hang. (And yes, we have a user who appears to have over 100,000 unsent events. Not sure how.)


bjhomer commented 3 months ago

Have you considered moving the call to a dedicated queue? Just curious if you found issues with changing queue or if it's something that wasn't considered in the interest of getting the fix out.

Yeah, I think I would like to move it to another queue, but I was going for a smaller change in the interest of getting a fix out sooner.

bjhomer commented 3 months ago

And really, our events are already running on a background context… the problem is that because the main thread still needs to access that context (via -performAndWait or -perform), the main thread can be blocked if the context is busy doing something else on another thread.

A better solution would probably want to have two separate contexts; one for writing, and one for reading. But that seems quite a bit more complex than what I have time to allocate to this at the moment. :)