From 01742af16b8a07254aea97994752a740f04e5a36 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Mon, 21 Mar 2022 17:18:12 +1100 Subject: [PATCH] Added an initial call to `isRTL` on the main thread to prevent a background thread calling it first --- Session/Home/HomeVC.swift | 6 ++++++ Session/Meta/MainAppContext.m | 1 + 2 files changed, 7 insertions(+) diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift index da9153682..8bbc7a523 100644 --- a/Session/Home/HomeVC.swift +++ b/Session/Home/HomeVC.swift @@ -84,6 +84,12 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv // MARK: Lifecycle override func viewDidLoad() { super.viewDidLoad() + + // Note: This is a hack to ensure `isRTL` is initially gets run on the main thread so the value is cached (it gets + // called on background threads and if it hasn't cached the value then it can cause odd performance issues since + // it accesses UIKit) + _ = CurrentAppContext().isRTL + // Threads (part 1) dbConnection.beginLongLivedReadTransaction() // Freeze the connection for use on the main thread (this gives us a stable data source that doesn't change until we tell it to) // Preparation diff --git a/Session/Meta/MainAppContext.m b/Session/Meta/MainAppContext.m index 66948daf6..2fad58d41 100644 --- a/Session/Meta/MainAppContext.m +++ b/Session/Meta/MainAppContext.m @@ -166,6 +166,7 @@ NSString *const ReportedApplicationStateDidChangeNotification = @"ReportedApplic - (BOOL)isRTL { + // FIXME: We should try to remove this as we've had to add a hack to ensure the first call to this runs on the main thread static BOOL isRTL = NO; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{