TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8.02k stars 1.29k forks source link

ASCollectionNode BatchUpdates are slow #93

Open stapleup opened 7 years ago

stapleup commented 7 years ago

Hi, We are experiencing some very weird behaviour where ASCollectionNode batchUpdates take 4-5 seconds to complete and during that time our UI is completely blocked (We are using the version 2.3 of Texture). We took the ASDKGram example and added a content view screen (users can click on an item and get to a screen where content is displayed in full screen, they can like a content and the data is updated in current and previous controllers). On most recent iOS version the lag is very little, but it is still noticeable, on an iPhone 5S running iOS 8, the batch updates take a while to complete and during that time the UI is completely unresponsive.

We initially thought that it could be related to how we were handling the whole process of inserting and deleting rows, but it appears even calling the function with no updates is causing the delay.

 collectionNode.performBatch(animated: false, updates: {

}, completion: { completion in

})

By using the time profiler, it appears that ASSubclassOverridesSelector is the one taking up most of the time when the performBatch is called.

Any help in this regard would be helpful because this is the only thing causing lag in whole application as rest of the app runs smoothly thanks to AsyncDisplayKit / Texture.

Regards

maicki commented 7 years ago

@stapleup Hey! To dive deeper into that would it be possible you could add an Instrument trace to this issue. Thanks!

stapleup commented 7 years ago

@maicki , thank you for responding, please see the below trace.

8.81 s   40.6%  0 s       Main Thread  0x325ee
2.91 s   13.4%  0 s        main
305.00 ms    1.4%   0 s        -[ASLayout .cxx_destruct]
128.00 ms    0.5%   0 s         ASDisplayNodeLayout::~ASDisplayNodeLayout()
128.00 ms    0.5%   0 s          ASDisplayNodeLayout::~ASDisplayNodeLayout()
128.00 ms    0.5%   0 s           std::__1::__shared_ptr_emplace<ASDisplayNodeLayout, std::__1::allocator<ASDisplayNodeLayout> >::__on_zero_shared()
128.00 ms    0.5%   0 s            std::__1::shared_ptr<ASDisplayNodeLayout>::~shared_ptr()
128.00 ms    0.5%   0 s             std::__1::shared_ptr<ASDisplayNodeLayout>::~shared_ptr()
75.00 ms    0.3%    0 s              std::__1::shared_ptr<ASDisplayNodeLayout>::operator=(std::__1::shared_ptr<ASDisplayNodeLayout>&&)
75.00 ms    0.3%    0 s               -[ASDisplayNode layoutThatFits:parentSize:]
41.00 ms    0.1%    0 s                crossChildLayout(ASStackLayoutSpecChild const&, ASStackLayoutSpecStyle const&, double, double, double, double, CGSize)
41.00 ms    0.1%    0 s                 ___ZL43layoutItemsAlongUnconstrainedStackDimensionRNSt3__16vectorI21ASStackLayoutSpecItemNS_9allocatorIS1_EEEERK22ASStackLayoutSpecStylebRK11ASSizeRange6CGSizeb_block_invoke
41.00 ms    0.1%    0 s                  dispatchApplyIfNeeded(unsigned long, bool, void (unsigned long) block_pointer)
41.00 ms    0.1%    0 s                   layoutItemsAlongUnconstrainedStackDimension(std::__1::vector<ASStackLayoutSpecItem, std::__1::allocator<ASStackLayoutSpecItem> >&, ASStackLayoutSpecStyle const&, bool, ASSizeRange const&, CGSize, bool)
41.00 ms    0.1%    0 s                    ASStackUnpositionedLayout::compute(std::__1::vector<ASStackLayoutSpecChild, std::__1::allocator<ASStackLayoutSpecChild> > const&, ASStackLayoutSpecStyle const&, ASSizeRange const&, bool)
41.00 ms    0.1%    0 s                     -[ASStackLayoutSpec calculateLayoutThatFits:]
41.00 ms    0.1%    0 s                      -[ASLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:]
41.00 ms    0.1%    0 s                       -[ASLayoutSpec layoutThatFits:parentSize:]
19.00 ms    0.0%    0 s                        crossChildLayout(ASStackLayoutSpecChild const&, ASStackLayoutSpecStyle const&, double, double, double, double, CGSize)
19.00 ms    0.0%    0 s                         ___ZL43layoutItemsAlongUnconstrainedStackDimensionRNSt3__16vectorI21ASStackLayoutSpecItemNS_9allocatorIS1_EEEERK22ASStackLayoutSpecStylebRK11ASSizeRange6CGSizeb_block_invoke
19.00 ms    0.0%    0 s                          dispatchApplyIfNeeded(unsigned long, bool, void (unsigned long) block_pointer)
19.00 ms    0.0%    0 s                           layoutItemsAlongUnconstrainedStackDimension(std::__1::vector<ASStackLayoutSpecItem, std::__1::allocator<ASStackLayoutSpecItem> >&, ASStackLayoutSpecStyle const&, bool, ASSizeRange const&, CGSize, bool)
19.00 ms    0.0%    0 s                            ASStackUnpositionedLayout::compute(std::__1::vector<ASStackLayoutSpecChild, std::__1::allocator<ASStackLayoutSpecChild> > const&, ASStackLayoutSpecStyle const&, ASSizeRange const&, bool)
19.00 ms    0.0%    0 s                             -[ASStackLayoutSpec calculateLayoutThatFits:]
19.00 ms    0.0%    0 s                              -[ASLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:]
19.00 ms    0.0%    0 s                               -[ASLayoutSpec layoutThatFits:parentSize:]
14.00 ms    0.0%    0 s                                crossChildLayout(ASStackLayoutSpecChild const&, ASStackLayoutSpecStyle const&, double, double, double, double, CGSize)
14.00 ms    0.0%    0 s                                 ___ZL43layoutItemsAlongUnconstrainedStackDimensionRNSt3__16vectorI21ASStackLayoutSpecItemNS_9allocatorIS1_EEEERK22ASStackLayoutSpecStylebRK11ASSizeRange6CGSizeb_block_invoke
14.00 ms    0.0%    0 s                                  dispatchApplyIfNeeded(unsigned long, bool, void (unsigned long) block_pointer)
14.00 ms    0.0%    0 s                                   layoutItemsAlongUnconstrainedStackDimension(std::__1::vector<ASStackLayoutSpecItem, std::__1::allocator<ASStackLayoutSpecItem> >&, ASStackLayoutSpecStyle const&, bool, ASSizeRange const&, CGSize, bool)
14.00 ms    0.0%    0 s                                    ASStackUnpositionedLayout::compute(std::__1::vector<ASStackLayoutSpecChild, std::__1::allocator<ASStackLayoutSpecChild> > const&, ASStackLayoutSpecStyle const&, ASSizeRange const&, bool)
14.00 ms    0.0%    0 s                                     -[ASStackLayoutSpec calculateLayoutThatFits:]
14.00 ms    0.0%    0 s                                      -[ASLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:]
14.00 ms    0.0%    0 s                                       -[ASLayoutSpec layoutThatFits:parentSize:]
14.00 ms    0.0%    0 s                                        -[ASInsetLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:]
14.00 ms    0.0%    0 s                                         -[ASLayoutSpec layoutThatFits:parentSize:]
14.00 ms    0.0%    0 s                                          crossChildLayout(ASStackLayoutSpecChild const&, ASStackLayoutSpecStyle const&, double, double, double, double, CGSize)
14.00 ms    0.0%    0 s                                           ___ZL43layoutItemsAlongUnconstrainedStackDimensionRNSt3__16vectorI21ASStackLayoutSpecItemNS_9allocatorIS1_EEEERK22ASStackLayoutSpecStylebRK11ASSizeRange6CGSizeb_block_invoke
14.00 ms    0.0%    0 s                                            dispatchApplyIfNeeded(unsigned long, bool, void (unsigned long) block_pointer)
14.00 ms    0.0%    0 s                                             layoutItemsAlongUnconstrainedStackDimension(std::__1::vector<ASStackLayoutSpecItem, std::__1::allocator<ASStackLayoutSpecItem> >&, ASStackLayoutSpecStyle const&, bool, ASSizeRange const&, CGSize, bool)
14.00 ms    0.0%    0 s                                              ASStackUnpositionedLayout::compute(std::__1::vector<ASStackLayoutSpecChild, std::__1::allocator<ASStackLayoutSpecChild> > const&, ASStackLayoutSpecStyle const&, ASSizeRange const&, bool)
14.00 ms    0.0%    0 s                                               -[ASStackLayoutSpec calculateLayoutThatFits:]
14.00 ms    0.0%    0 s                                                -[ASLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:]
14.00 ms    0.0%    0 s                                                 -[ASLayoutSpec layoutThatFits:parentSize:]
14.00 ms    0.0%    0 s                                                  -[ASLayoutSpec layoutThatFits:]
14.00 ms    0.0%    0 s                                                   -[ASDisplayNode calculateLayoutThatFits:]
14.00 ms    0.0%    0 s                                                    -[ASDisplayNode calculateLayoutThatFits:restrictedToSize:relativeToParentSize:]
14.00 ms    0.0%    0 s                                                     -[ASDisplayNode layoutThatFits:parentSize:]
14.00 ms    0.0%    0 s                                                      -[ASDisplayNode measureWithSizeRange:]
14.00 ms    0.0%    0 s                                                       -[ASDisplayNode layoutThatFits:]
14.00 ms    0.0%    0 s                                                        -[ASCollectionView sizeForElement:]
14.00 ms    0.0%    0 s                                                         -[ASCollectionView collectionView:layout:sizeForItemAtIndexPath:]
14.00 ms    0.0%    0 s                                                          -[ASCollectionView _superPerformBatchUpdates:completion:]
14.00 ms    0.0%    0 s                                                           __59-[ASCollectionView rangeController:didUpdateWithChangeSet:]_block_invoke
14.00 ms    0.0%    0 s                                                            ASPerformBlockWithoutAnimation(bool, void () block_pointer)
14.00 ms    0.0%    0 s                                                             -[ASCollectionView rangeController:didUpdateWithChangeSet:]
14.00 ms    0.0%    0 s                                                              -[ASRangeController dataController:didUpdateWithChangeSet:]
14.00 ms    0.0%    0 s                                                               __40-[ASDataController updateWithChangeSet:]_block_invoke_3
14.00 ms    0.0%    0 s                                                                __30-[ASMainSerialQueue runBlocks]_block_invoke
14.00 ms    0.0%    0 s                                                                 ASPerformBlockOnMainThread
14.00 ms    0.0%    0 s                                                                  -[ASMainSerialQueue runBlocks]
14.00 ms    0.0%    0 s                                                                   -[ASMainSerialQueue performBlockOnMainThread:]
14.00 ms    0.0%    0 s                                                                    -[ASDataController _scheduleBlockOnMainSerialQueue:]
14.00 ms    0.0%    0 s                                                                     -[ASDataController waitUntilAllUpdatesAreCommitted]
14.00 ms    0.0%    0 s                                                                      -[ASCollectionView waitUntilAllUpdatesAreCommitted]
14.00 ms    0.0%    0 s                                                                       -[ASCollectionView convertIndexPathFromCollectionNode:waitingIfNeeded:]
14.00 ms    0.0%    0 s                                                                        -[ASCollectionNode scrollToItemAtIndexPath:atScrollPosition:animated:]
14.00 ms    0.0%    0 s                                                                         -[ASCollectionNode scrollToItemAtIndexPath:atScrollPosition:animated:]
14.00 ms    0.0%    0 s                                                                          ListingViewController.ContentViewControllerEndedAtIndex(index : Int, next : String) -> ()
14.00 ms    0.0%    0 s                                                                           protocol witness for ContentViewControllerDelegate.ContentViewControllerEndedAtIndex(index : Int, next : String) -> () in conformance ListingViewController
14.00 ms    0.0%    0 s                                                                            ContentViewController.viewWillDisappear(Bool) -> ()
14.00 ms    0.0%    0 s                                                                             @objc ContentViewController.viewWillDisappear(Bool) -> ()