From 1832d79bd19d527d25424411a0ef13c0df0e9158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Po=CC=88tzschke?= Date: Thu, 10 Mar 2016 07:45:17 -0800 Subject: [PATCH] TextStorage in RCTText is now only set when it differs from old value. Summary:**Motivation** Multiple instances of `Text` inside a `ListView` is a bad idea for the performance of the app. When you create 1000 elements and you scroll through the list it is really slow and laggy because the `NSTextStorage`, which is the backbone of the `RCTText` element, will set more than 1,000 times and also the method `setNeedsDisplay` is called multiple times. This will causes huge memory problems and the app crashes. With this commit I check in `RCTText` if the `NSTextStorage` differs from the old value. If yes then set it otherwise don't set the `NSTextStorage`. This will prevent to call `setNeedsDisplay` when not really needed. Gist with sample app to show behavior can be found here: https://gist.github.com/bpoetzschke/28a17969c6aa54219e18 Closes https://github.com/facebook/react-native/pull/6341 Differential Revision: D3035485 Pulled By: nicklockwood fb-gh-sync-id: 181f01b7f87f765dbb01a4ad3196fc40f9d50694 shipit-source-id: 181f01b7f87f765dbb01a4ad3196fc40f9d50694 --- Libraries/Text/RCTText.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/Text/RCTText.m b/Libraries/Text/RCTText.m index a4f110ed6..e57b93aa1 100644 --- a/Libraries/Text/RCTText.m +++ b/Libraries/Text/RCTText.m @@ -74,8 +74,10 @@ - (void)setTextStorage:(NSTextStorage *)textStorage { - _textStorage = textStorage; - [self setNeedsDisplay]; + if (_textStorage != textStorage) { + _textStorage = textStorage; + [self setNeedsDisplay]; + } } - (void)drawRect:(CGRect)rect