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

Ship ASExperimentalImageDownloaderPriority #1480

Merged
Show file tree
Hide file tree
Changes from 3 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: 0 additions & 1 deletion Schemas/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"exp_did_enter_preload_skip_asm_layout",
"exp_disable_a11y_cache",
"exp_dispatch_apply",
"exp_image_downloader_priority",
"exp_text_drawing",
"exp_fix_range_controller",
"exp_oom_bg_dealloc_disable",
Expand Down
11 changes: 5 additions & 6 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalDidEnterPreloadSkipASMLayout = 1 << 7, // exp_did_enter_preload_skip_asm_layout
ASExperimentalDisableAccessibilityCache = 1 << 8, // exp_disable_a11y_cache
ASExperimentalDispatchApply = 1 << 9, // exp_dispatch_apply
ASExperimentalImageDownloaderPriority = 1 << 10, // exp_image_downloader_priority
ASExperimentalTextDrawing = 1 << 11, // exp_text_drawing
ASExperimentalFixRangeController = 1 << 12, // exp_fix_range_controller
ASExperimentalOOMBackgroundDeallocDisable = 1 << 13, // exp_oom_bg_dealloc_disable
ASExperimentalTransactionOperationRetainCycle = 1 << 14, // exp_transaction_operation_retain_cycle
ASExperimentalRemoveTextKitInitialisingLock = 1 << 15, // exp_remove_textkit_initialising_lock
ASExperimentalTextDrawing = 1 << 10, // exp_text_drawing
ASExperimentalFixRangeController = 1 << 11, // exp_fix_range_controller
ASExperimentalOOMBackgroundDeallocDisable = 1 << 12, // exp_oom_bg_dealloc_disable
ASExperimentalTransactionOperationRetainCycle = 1 << 13, // exp_transaction_operation_retain_cycle
ASExperimentalRemoveTextKitInitialisingLock = 1 << 14, // exp_remove_textkit_initialising_lock
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
1 change: 0 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@"exp_did_enter_preload_skip_asm_layout",
@"exp_disable_a11y_cache",
@"exp_dispatch_apply",
@"exp_image_downloader_priority",
@"exp_text_drawing",
@"exp_fix_range_controller",
@"exp_oom_bg_dealloc_disable",
Expand Down
42 changes: 17 additions & 25 deletions Source/ASMultiplexImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -279,31 +279,29 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
{
[super displayWillStartAsynchronously:asynchronously];
[self didEnterPreloadState];
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityImminent];
[self _updatePriorityOnDownloaderIfNeeded];
}

/* didEnterVisibleState / didExitVisibleState in ASNetworkImageNode has a very similar implementation. Changes here are likely necessary
in ASNetworkImageNode as well. */
- (void)didEnterVisibleState
{
[super didEnterVisibleState];
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityVisible];
[self _updatePriorityOnDownloaderIfNeeded];
[self _updateProgressImageBlockOnDownloaderIfNeeded];
}

- (void)didExitVisibleState
{
[super didExitVisibleState];
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityPreload];
[self _updatePriorityOnDownloaderIfNeeded];
[self _updateProgressImageBlockOnDownloaderIfNeeded];
}

- (void)didExitDisplayState
{
[super didExitDisplayState];
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityPreload];
}
[self _updatePriorityOnDownloaderIfNeeded];
}

#pragma mark - Core
Expand Down Expand Up @@ -484,7 +482,7 @@ - (UIImage *)_bestImmediatelyAvailableImageFromDataSource:(id *)imageIdentifierO

#pragma mark -

- (void)_updatePriorityOnDownloaderIfNeededWithDefaultPriority:(ASImageDownloaderPriority)defaultPriority
- (void)_updatePriorityOnDownloaderIfNeeded
{
DISABLED_ASAssertUnlocked(_downloadIdentifierLock);

Expand All @@ -494,11 +492,7 @@ - (void)_updatePriorityOnDownloaderIfNeededWithDefaultPriority:(ASImageDownloade
MutexLocker l(_downloadIdentifierLock);

if (_downloadIdentifier != nil) {
ASImageDownloaderPriority priority = defaultPriority;
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
priority = ASImageDownloaderPriorityWithInterfaceState(interfaceState);
}

ASImageDownloaderPriority priority = ASImageDownloaderPriorityWithInterfaceState(interfaceState);
[_downloader setPriority:priority withDownloadIdentifier:_downloadIdentifier];
}
}
Expand Down Expand Up @@ -872,14 +866,12 @@ - (void)_downloadImageWithIdentifier:(id)imageIdentifier URL:(NSURL *)imageURL c
dispatch_queue_t callbackQueue = dispatch_get_main_queue();

id downloadIdentifier;
if (strongSelf->_downloaderFlags.downloaderImplementsDownloadWithPriority
&& ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {

if (strongSelf->_downloaderFlags.downloaderImplementsDownloadWithPriority) {
/*
Decide a priority based on the current interface state of this node.
It can happen that this method was called when the node entered preload state
but the interface state, at this point, tells us that the node is (going to be) visible,
If that's the case, we jump to a higher priority directly.
Decide a priority based on the current interface state of this node.
It can happen that this method was called when the node entered preload state
but the interface state, at this point, tells us that the node is (going to be) visible,
If that's the case, we jump to a higher priority directly.
*/
ASImageDownloaderPriority priority = ASImageDownloaderPriorityWithInterfaceState(strongSelf.interfaceState);
downloadIdentifier = [strongSelf->_downloader downloadImageWithURL:imageURL
Expand All @@ -889,13 +881,13 @@ - (void)_downloadImageWithIdentifier:(id)imageIdentifier URL:(NSURL *)imageURL c
completion:completion];
} else {
/*
Kick off a download with default priority.
The actual "default" value is decided by the downloader.
ASBasicImageDownloader and ASPINRemoteImageDownloader both use ASImageDownloaderPriorityImminent
which is mapped to NSURLSessionTaskPriorityDefault.
Kick off a download with default priority.
The actual "default" value is decided by the downloader.
ASBasicImageDownloader and ASPINRemoteImageDownloader both use ASImageDownloaderPriorityImminent
which is mapped to NSURLSessionTaskPriorityDefault.

This means that preload and display nodes use the same priority
and their requests are put into the same pool.
This means that preload and display nodes use the same priority
and their requests are put into the same pool.
*/
downloadIdentifier = [strongSelf->_downloader downloadImageWithURL:imageURL
callbackQueue:callbackQueue
Expand Down
23 changes: 8 additions & 15 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
}

if (self.image == nil) {
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityImminent];
[self _updatePriorityOnDownloaderIfNeeded];
}
}

Expand All @@ -381,23 +381,21 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
- (void)didEnterVisibleState
{
[super didEnterVisibleState];
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityVisible];
[self _updatePriorityOnDownloaderIfNeeded];
[self _updateProgressImageBlockOnDownloaderIfNeeded];
}

- (void)didExitVisibleState
{
[super didExitVisibleState];
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityPreload];
[self _updatePriorityOnDownloaderIfNeeded];
[self _updateProgressImageBlockOnDownloaderIfNeeded];
}

- (void)didExitDisplayState
{
[super didExitDisplayState];
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
[self _updatePriorityOnDownloaderIfNeededWithDefaultPriority:ASImageDownloaderPriorityPreload];
}
[self _updatePriorityOnDownloaderIfNeeded];
}

- (void)didExitPreloadState
Expand Down Expand Up @@ -446,17 +444,13 @@ - (void)handleProgressImage:(UIImage *)progressImage progress:(CGFloat)progress
[self _locked__setImage:progressImage];
}

- (void)_updatePriorityOnDownloaderIfNeededWithDefaultPriority:(ASImageDownloaderPriority)defaultPriority
- (void)_updatePriorityOnDownloaderIfNeeded
{
if (_downloaderFlags.downloaderImplementsSetPriority) {
ASLockScopeSelf();

if (_downloadIdentifier != nil) {
ASImageDownloaderPriority priority = defaultPriority;
if (ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
priority = ASImageDownloaderPriorityWithInterfaceState(_interfaceState);
}

ASImageDownloaderPriority priority = ASImageDownloaderPriorityWithInterfaceState(_interfaceState);
[_downloader setPriority:priority withDownloadIdentifier:_downloadIdentifier];
}
}
Expand Down Expand Up @@ -598,8 +592,7 @@ - (void)_downloadImageWithCompletion:(void (^)(id <ASImageContainerProtocol> ima
}
};

if (self->_downloaderFlags.downloaderImplementsDownloadWithPriority
&& ASActivateExperimentalFeature(ASExperimentalImageDownloaderPriority)) {
if (self->_downloaderFlags.downloaderImplementsDownloadWithPriority) {
/*
Decide a priority based on the current interface state of this node.
It can happen that this method was called when the node entered preload state
Expand All @@ -620,7 +613,7 @@ - (void)_downloadImageWithCompletion:(void (^)(id <ASImageContainerProtocol> ima
ASBasicImageDownloader and ASPINRemoteImageDownloader both use ASImageDownloaderPriorityImminent
which is mapped to NSURLSessionTaskPriorityDefault.

This means that preload and display nodes use the same priority
This means that preload and display nodes use the same priority
and their requests are put into the same pool.
*/
downloadIdentifier = [self->_downloader downloadImageWithURL:url
Expand Down
2 changes: 0 additions & 2 deletions Tests/ASConfigurationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
ASExperimentalDidEnterPreloadSkipASMLayout,
ASExperimentalDisableAccessibilityCache,
ASExperimentalDispatchApply,
ASExperimentalImageDownloaderPriority,
ASExperimentalTextDrawing,
ASExperimentalFixRangeController,
ASExperimentalOOMBackgroundDeallocDisable,
Expand Down Expand Up @@ -56,7 +55,6 @@ + (NSArray *)names {
@"exp_did_enter_preload_skip_asm_layout",
@"exp_disable_a11y_cache",
@"exp_dispatch_apply",
@"exp_image_downloader_priority",
@"exp_text_drawing",
@"exp_fix_range_controller",
@"exp_oom_bg_dealloc_disable",
Expand Down