Skip to main content

Main-thread misuse

The main-thread misuse detector reports blocking work done on the main thread — the kind of call that causes stutter and, when it takes long enough, a hang. Each violation is filed as a non-fatal error report with the stack of the call.

Main-thread misuse detection is off by default.

Option keyBugseeOptionDetectAndReportMainThreadMisuse
BugseeOptions property— (set by key)
DefaultNO
BugseeOptions *options = [BugseeOptions defaultOptions];
[options updateLaunchOptions:@{
BugseeOptionDetectAndReportMainThreadMisuse : @YES,
}];

[Bugsee launchWithToken:@"<your_app_token>" options:options];

What gets flagged​

Bugsee intercepts these Foundation calls and reports the ones made on the main thread:

CategoryCallsDomain
Disk read+[NSData dataWithContentsOfFile:], +[NSData dataWithContentsOfURL:] and their options:error: variantsMainThreadMisuse::DiskRead
Disk write-[NSData writeToFile:atomically:], -[NSData writeToURL:atomically:] and their options:error: variantsMainThreadMisuse::DiskWrite
UserDefaults-[NSUserDefaults synchronize]MainThreadMisuse::UserDefaults
Network+[NSURLConnection sendSynchronousRequest:returningResponse:error:]MainThreadMisuse::Network

Bugsee's own file access is never reported.

Objective-C entry points only

The detector intercepts the Objective-C methods above, so it does not see:

  • Swift's Foundation calls such as Data(contentsOf:), data.write(to:) and String(contentsOfFile:), which do not go through these methods.
  • -[NSData initWithContentsOfFile:] and -[NSData initWithContentsOfURL:].
  • FileManager / NSFileManager, streams, POSIX file I/O, and a URLSession request waited on with a semaphore.

A clean result does not mean the main thread does no blocking work.

The report​

FieldValue
TypeError (non-fatal), with the error priority (BugseeOptionReportingDefaultErrorPriority)
SummaryDisk read on main thread, Disk write on main thread, UserDefaults access on main thread or Network operation on main thread
DomainOne of the domains above
StackThe call stack at the violation. The issue is titled after its top frame, the violating call site

Each call site is reported once per session, identified by the first frame of the stack outside the SDK. Stopping Bugsee starts a new session.

On the simulator and Mac Catalyst, the detector installs nothing and reports nothing.

Found an issue, typo, or wrong statement on this page? Report it now →