diff --git a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m index 260e31d50..4317e8b7a 100644 --- a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m +++ b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m @@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN + (YapDatabaseConnection *)dbReadConnection { - // OWSAssert(![NSThread isMainThread]); + OWSJanksUI(); // We use TSYapDatabaseObject's dbReadWriteConnection (not OWSPrimaryStorage's // dbReadConnection) for consistency, since we tend to [TSYapDatabaseObject @@ -121,7 +121,7 @@ NS_ASSUME_NONNULL_BEGIN + (YapDatabaseConnection *)dbReadWriteConnection { - // OWSAssert(![NSThread isMainThread]); + OWSJanksUI(); // Use a dedicated connection for model reads & writes. static YapDatabaseConnection *dbReadWriteConnection = nil; diff --git a/SignalServiceKit/src/Util/OWSAsserts.h b/SignalServiceKit/src/Util/OWSAsserts.h index c9f34a660..84be8e747 100755 --- a/SignalServiceKit/src/Util/OWSAsserts.h +++ b/SignalServiceKit/src/Util/OWSAsserts.h @@ -150,4 +150,26 @@ void SwiftAssertIsOnMainThread(NSString *functionName); userInfo:userInfoParam]; \ } + +// UI JANK +// +// In pursuit of smooth UI, we want to continue moving blocking operations off the main thread. +// Add `OWSJanksUI` in code paths that shouldn't be called on the main thread. +// Because we have pervasively broken this tenant, enabling it by default would be too disruptive +// but it's helpful while unjanking and maybe someday we can have it enabled by default. +//#define DEBUG_UI_JANK 1 + +#ifdef DEBUG +#ifdef DEBUG_UI_JANK +#define OWSJanksUI() \ + do { \ + OWSAssert(![NSThread isMainThread]) \ + } while (NO) +#endif +#endif + +#ifndef OWSJanksUI +#define OWSJanksUI() +#endif + NS_ASSUME_NONNULL_END