From f51416b2d2f4419eddc39834c983a902947dda82 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 14 Dec 2018 16:56:34 -0700 Subject: [PATCH 1/2] save a few ms on send, hoist async dispatch to caller, and use it for clearing draft --- .../ConversationInputToolbar.m | 16 +++++----------- .../ConversationViewController.m | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 139785cdb..8423b5add 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -222,17 +222,11 @@ const CGFloat kMaxTextViewHeight = 98; // Momentarily switch to a non-default keyboard, else reloadInputViews // will not affect the displayed keyboard. In practice this isn't perceptable to the user. // The alternative would be to dismiss-and-pop the keyboard, but that can cause a more pronounced animation. - // - // This is surprisingly expensive (~5ms), so we do it async, *after* the message is rendered. - dispatch_async(dispatch_get_main_queue(), ^{ - [BenchManager benchWithTitle:@"toggleDefaultKeyboard" block:^{ - self.inputTextView.keyboardType = UIKeyboardTypeNumbersAndPunctuation; - [self.inputTextView reloadInputViews]; - - self.inputTextView.keyboardType = UIKeyboardTypeDefault; - [self.inputTextView reloadInputViews]; - }]; - }); + self.inputTextView.keyboardType = UIKeyboardTypeNumbersAndPunctuation; + [self.inputTextView reloadInputViews]; + + self.inputTextView.keyboardType = UIKeyboardTypeDefault; + [self.inputTextView reloadInputViews]; } - (void)setQuotedReply:(nullable OWSQuotedReplyModel *)quotedReply diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 32e8d56ca..1b6346221 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3898,10 +3898,21 @@ typedef enum : NSUInteger { [self messageWasSent:message]; - if (updateKeyboardState) { - [self.inputToolbar toggleDefaultKeyboard]; - } - [self.inputToolbar clearTextMessageAnimated:YES]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [BenchManager benchWithTitle:@"toggleDefaultKeyboard" + block:^{ + if (updateKeyboardState) { + [self.inputToolbar toggleDefaultKeyboard]; + } + }]; + + [BenchManager benchWithTitle:@"clearTextMessageAnimated" + block:^{ + [self.inputToolbar clearTextMessageAnimated:YES]; + }]; + }); + [self clearDraft]; if (didAddToProfileWhitelist) { [self.conversationViewModel ensureDynamicInteractions]; From fd6a56b3afa9e833922d1e5879330a7d8a16e8b2 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 14 Dec 2018 17:05:10 -0700 Subject: [PATCH 2/2] format bench in ms --- SignalMessaging/utils/Bench.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SignalMessaging/utils/Bench.swift b/SignalMessaging/utils/Bench.swift index 580ebb33b..cf79debb5 100644 --- a/SignalMessaging/utils/Bench.swift +++ b/SignalMessaging/utils/Bench.swift @@ -18,7 +18,8 @@ public func BenchAsync(title: String, block: (@escaping () -> Void) -> Void) { block { let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime - Logger.debug("[Bench] title: \(title), duration: \(timeElapsed)") + let formattedTime = String(format: "%0.2fms", timeElapsed * 1000) + Logger.debug("[Bench] title: \(title), duration: \(formattedTime)") } }