From ea065625c8ba29cd3ba3caf2bc72b9ccef1ee687 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Fri, 22 Mar 2019 12:41:49 -0700 Subject: [PATCH] Follow up on the ASRangeController fix in #1418 (#1419) The changes in #1418 is a bit too aggressive when it comes to nodes that are in display range. It forces those nodes to not preload. Also update the changes to avoid diluting the experiment data by triggering too broadly (i.e avoid triggering when the old and new implementations yield the same result leading to no behavior change). --- Source/Details/ASRangeController.mm | 31 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Source/Details/ASRangeController.mm b/Source/Details/ASRangeController.mm index 5625fd59e..63a5562ad 100644 --- a/Source/Details/ASRangeController.mm +++ b/Source/Details/ASRangeController.mm @@ -351,25 +351,34 @@ - (void)_updateVisibleNodeIndexPaths } else { // If selfInterfaceState isn't visible, then visibleIndexPaths represents either what /will/ be immediately visible at the // instant we come onscreen, or what /will/ no longer be visible at the instant we come offscreen. - // So, preload and display all of those things, but don't waste resources preloading others. - // We handle this as a separate case to minimize set operations, including -containsObject:. + // So, preload and display all of those things, but don't waste resources displaying others. // // DO NOT set Visible: even though these elements are in the visible range / "viewport", // our overall container object is itself not yet, or no longer, visible. // The moment it becomes visible, we will run the condition above. - BOOL shouldUpdateInterfaceState = NO; - if (ASActivateExperimentalFeature(ASExperimentalFixRangeController)) { - shouldUpdateInterfaceState = [visibleIndexPaths containsObject:indexPath]; - } else { - shouldUpdateInterfaceState = [allCurrentIndexPaths containsObject:indexPath]; + ASInterfaceState interfaceStateBeforeFix = interfaceState; + if ([allCurrentIndexPaths containsObject:indexPath]) { + interfaceStateBeforeFix |= ASInterfaceStatePreload; + if (rangeMode != ASLayoutRangeModeLowMemory) { + interfaceStateBeforeFix |= ASInterfaceStateDisplay; + } } - - if (shouldUpdateInterfaceState) { - interfaceState |= ASInterfaceStatePreload; + + ASInterfaceState interfaceStateAfterFix = interfaceState; + if ([visibleIndexPaths containsObject:indexPath]) { + interfaceStateAfterFix |= ASInterfaceStatePreload; if (rangeMode != ASLayoutRangeModeLowMemory) { - interfaceState |= ASInterfaceStateDisplay; + interfaceStateAfterFix |= ASInterfaceStateDisplay; } + } else if ([displayIndexPaths containsObject:indexPath]) { + interfaceStateAfterFix |= ASInterfaceStatePreload; + } + + if (interfaceStateBeforeFix != interfaceStateAfterFix && ASActivateExperimentalFeature(ASExperimentalFixRangeController)) { + interfaceState = interfaceStateAfterFix; + } else { + interfaceState = interfaceStateBeforeFix; } }