mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-15 18:59:54 +00:00
[ASDisplayNode] -didEnterPreloadState does not need to call -layoutIfNeeded #trivial (#411)
This was originally added for ASCollectionNode and ASTableNode preloading to work as intended when nested inside of another ASRangeController-powered node. Indeed, it is still necessary to trigger layout on these UIKit-backed components in order for their own ASRangeControllers to start preparing content within them. However, unlike the comment suggests, it is *not* necessary to do this for image nodes. ASNetworkImageNode has only one .URL, and does not use the .bounds or .calculatedLayout at all during loading. Even the ASMultiplexImageNode does not use the .bounds, and the ASMapNode uses .calculatedLayout instead of .bounds. This change has important performance benefits. In particular, it avoids layouts that would occur on the main thread, often including text sizing, and also can result in redundant layout passes (even during a layout pass that triggers a node to enter the preload range, it may force its own layout early). It would be great to test this change with Pinterest to confirm its safety, but based on a full audit of the framework codebase, the only possibility that I see for a regression is if app implementations of -didEnterPreloadState make direct use of .bounds instead of .calculatedLayout (which is easy to fix).
This commit is contained in:
parent
ed9a3cc2e0
commit
03592e0669
@ -213,10 +213,10 @@
|
||||
|
||||
- (void)didEnterPreloadState
|
||||
{
|
||||
// Intentionally allocate the view here so that super will trigger a layout pass on it which in turn will trigger the intial data load.
|
||||
// We can get rid of this call later when ASDataController, ASRangeController and ASCollectionLayout can operate without the view.
|
||||
[self view];
|
||||
[super didEnterPreloadState];
|
||||
// Intentionally allocate the view here and trigger a layout pass on it, which in turn will trigger the intial data load.
|
||||
// We can get rid of this call later when ASDataController, ASRangeController and ASCollectionLayout can operate without the view.
|
||||
[[self view] layoutIfNeeded];
|
||||
}
|
||||
|
||||
#if ASRangeControllerLoggingEnabled
|
||||
|
||||
@ -2938,10 +2938,6 @@ ASDISPLAYNODE_INLINE BOOL subtreeIsRasterized(ASDisplayNode *node) {
|
||||
ASDisplayNodeAssertLockUnownedByCurrentThread(__instanceLock__);
|
||||
[_interfaceStateDelegate didEnterPreloadState];
|
||||
|
||||
// Trigger a layout pass to ensure all subnodes have the correct size to preload their content.
|
||||
// This is important for image nodes, as well as collection and table nodes.
|
||||
[self layoutIfNeeded];
|
||||
|
||||
if (_methodOverrides & ASDisplayNodeMethodOverrideFetchData) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
@ -142,10 +142,10 @@
|
||||
|
||||
- (void)didEnterPreloadState
|
||||
{
|
||||
// Intentionally allocate the view here so that super will trigger a layout pass on it which in turn will trigger the intial data load.
|
||||
// We can get rid of this call later when ASDataController, ASRangeController and ASCollectionLayout can operate without the view.
|
||||
[self view];
|
||||
[super didEnterPreloadState];
|
||||
// Intentionally allocate the view here and trigger a layout pass on it, which in turn will trigger the intial data load.
|
||||
// We can get rid of this call later when ASDataController, ASRangeController and ASCollectionLayout can operate without the view.
|
||||
[[self view] layoutIfNeeded];
|
||||
}
|
||||
|
||||
#if ASRangeControllerLoggingEnabled
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user