From c617b18eb614a8fafdac6788add646b49fc63015 Mon Sep 17 00:00:00 2001 From: Zhisheng Huang Date: Mon, 5 Feb 2018 12:21:27 -0800 Subject: [PATCH] Move the DEBUG uniqueness check outside of for-loop inside IGListAdapter Summary: The original DEBUG was put inside a for loop, which caused a quadratic looping while creating bigger and bigger NSSet. This is very inefficient and I verified that by profiling with 10000 objects in the array and it caused significant amount of CPU. The main thread is pretty much unresponsive. Closes https://github.com/Instagram/IGListKit/pull/1084 Reviewed By: rnystrom Differential Revision: D6903043 Pulled By: lorixx fbshipit-source-id: 311e8a402eb8d5574fce0eabd626a674b6a5e8c5 --- Source/IGListAdapter.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/IGListAdapter.m b/Source/IGListAdapter.m index 7582c699..a95c3d96 100644 --- a/Source/IGListAdapter.m +++ b/Source/IGListAdapter.m @@ -621,13 +621,13 @@ } [sectionControllers addObject:sectionController]; - -#if DEBUG - IGAssert([NSSet setWithArray:sectionControllers].count == sectionControllers.count, - @"Section controllers array is not filled with unique objects; section controllers are being reused"); -#endif [validObjects addObject:object]; } + +#if DEBUG + IGAssert([NSSet setWithArray:sectionControllers].count == sectionControllers.count, + @"Section controllers array is not filled with unique objects; section controllers are being reused"); +#endif // clear the view controller and collection context IGListSectionControllerPopThread();