Skip to content

Commit

Permalink
Create an experiment to remove extra collection teardown step (#975)
Browse files Browse the repository at this point in the history
* Create an experiment to remove extra collection teardown step, simplify delegate proxy

* chagelog

* Remove detritus
  • Loading branch information
Adlai-Holler authored Jun 19, 2018
1 parent 4669a24 commit a0e5f4c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
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: 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

0 comments on commit a0e5f4c

Please sign in to comment.