Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an experiment to remove extra collection teardown step #975

Merged
merged 3 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Reduce usage of autorelease pools. [Adlai Holler](https://github.com/Adlai-Holler) [#968](https://github.com/TextureGroup/Texture/pull/968)
- Clean up unused/unneeded header macros. [Adlai Holler](https://github.com/Adlai-Holler)
- Clean up C-function `extern` decorators. [Adlai Holler](https://github.com/Adlai-Holler)
- Add an experiment to reduce work involved in collection teardown. [Adlai Holler](https://github.com/Adlai-Holler)

## 2.7
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)
Expand Down
3 changes: 2 additions & 1 deletion Schemas/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"exp_unfair_lock",
"exp_infer_layer_defaults",
"exp_network_image_queue",
"exp_dealloc_queue_v2"
"exp_dealloc_queue_v2",
"exp_collection_teardown",
]
}
}
Expand Down
6 changes: 4 additions & 2 deletions Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ - (void)dealloc

// Sometimes the UIKit classes can call back to their delegate even during deallocation, due to animation completion blocks etc.
_isDeallocating = YES;
[self setAsyncDelegate:nil];
[self setAsyncDataSource:nil];
if (!ASActivateExperimentalFeature(ASExperimentalCollectionTeardown)) {
[self setAsyncDelegate:nil];
[self setAsyncDataSource:nil];
}

// Data controller & range controller may own a ton of nodes, let's deallocate those off-main.
ASPerformBackgroundDeallocation(&_dataController);
Expand Down
1 change: 1 addition & 0 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalLayerDefaults = 1 << 4, // exp_infer_layer_defaults
ASExperimentalNetworkImageQueue = 1 << 5, // exp_network_image_queue
ASExperimentalDeallocQueue = 1 << 6, // exp_dealloc_queue_v2
ASExperimentalCollectionTeardown = 1 << 7, // exp_collection_teardown
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
3 changes: 2 additions & 1 deletion Source/ASExperimentalFeatures.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
@"exp_unfair_lock",
@"exp_infer_layer_defaults",
@"exp_network_image_queue",
@"exp_dealloc_queue_v2"]));
@"exp_dealloc_queue_v2",
@"exp_collection_teardown"]));

if (flags == ASExperimentalFeatureAll) {
return allNames;
Expand Down
7 changes: 5 additions & 2 deletions Source/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import <AsyncDisplayKit/ASBatchFetching.h>
#import <AsyncDisplayKit/ASCellNode+Internal.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASConfigurationInternal.h>
#import <AsyncDisplayKit/ASDelegateProxy.h>
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
Expand Down Expand Up @@ -371,8 +372,10 @@ - (void)dealloc

// Sometimes the UIKit classes can call back to their delegate even during deallocation.
_isDeallocating = YES;
[self setAsyncDelegate:nil];
[self setAsyncDataSource:nil];
if (!ASActivateExperimentalFeature(ASExperimentalCollectionTeardown)) {
[self setAsyncDelegate:nil];
[self setAsyncDataSource:nil];
}

// Data controller & range controller may own a ton of nodes, let's deallocate those off-main
ASPerformBackgroundDeallocation(&_dataController);
Expand Down
2 changes: 2 additions & 0 deletions Source/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,8 @@ - (void)clearData
ASDisplayNodeAssertMainThread();
if (_initialReloadDataHasBeenCalled) {
[self waitUntilAllUpdatesAreProcessed];
auto vis = self.visibleMap;
auto pending = self.pendingMap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed!

self.visibleMap = self.pendingMap = [[ASElementMap alloc] init];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASDelegateProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

@interface ASDelegateProxy : NSProxy

- (instancetype)initWithTarget:(id <NSObject>)target interceptor:(id <ASDelegateProxyInterceptor>)interceptor;
- (instancetype)initWithTarget:(id)target interceptor:(id <ASDelegateProxyInterceptor>)interceptor;

// This method must be overridden by a subclass.
- (BOOL)interceptsSelector:(SEL)selector;
Expand Down
19 changes: 8 additions & 11 deletions Source/Details/ASDelegateProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,11 @@ - (BOOL)interceptsSelector:(SEL)selector

@implementation ASDelegateProxy {
id <ASDelegateProxyInterceptor> __weak _interceptor;
id <NSObject> __weak _target;
id __weak _target;
}

- (instancetype)initWithTarget:(id <NSObject>)target interceptor:(id <ASDelegateProxyInterceptor>)interceptor
- (instancetype)initWithTarget:(id)target interceptor:(id <ASDelegateProxyInterceptor>)interceptor
{
// -[NSProxy init] is undefined
if (!self) {
return nil;
}

ASDisplayNodeAssert(interceptor, @"interceptor must not be nil");

_target = target ? : [NSNull null];
Expand All @@ -161,8 +156,9 @@ - (instancetype)initWithTarget:(id <NSObject>)target interceptor:(id <ASDelegate

- (BOOL)conformsToProtocol:(Protocol *)aProtocol
{
if (_target) {
return [_target conformsToProtocol:aProtocol];
id target = _target;
if (target) {
return [target conformsToProtocol:aProtocol];
} else {
return [super conformsToProtocol:aProtocol];
}
Expand All @@ -183,8 +179,9 @@ - (id)forwardingTargetForSelector:(SEL)aSelector
if ([self interceptsSelector:aSelector]) {
return _interceptor;
} else {
if (_target) {
return [_target respondsToSelector:aSelector] ? _target : nil;
id target = _target;
if (target) {
return [target respondsToSelector:aSelector] ? target : nil;
} else {
// The _interceptor needs to be nilled out in this scenario. For that a strong reference needs to be created
// to be able to nil out the _interceptor but still let it know that the proxy target has deallocated
Expand Down