aptabase-swift icon indicating copy to clipboard operation
aptabase-swift copied to clipboard

Flush sync causes app to hang

Open Claeysson opened this issue 4 months ago • 3 comments

Performance issue

Sentry.io reports app hanging for over 2000ms when flushSync() is triggered.

Screenshot 2024-02-29 at 10 43 43

This code in aptabseClient.swift seems to be called on the main thread, and semaphore.wait() locks the main thread.

@objc private func flushSync() {
    let semaphore = DispatchSemaphore(value: 0)
    Task {
        await self.flush()
        semaphore.signal()
    }
    semaphore.wait()
}

Potential fix

I'm not quite sure why semaphore.wait() is used here. My best guess is that I will prevent a new flushSync if the latest hasn't finished executing. I've added a timer pause variable to mimic the wait but with out locking the main thread.

Claeysson avatar Feb 29 '24 09:02 Claeysson