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

A couple performance tweaks for animated images #trivial #634

Merged
merged 5 commits into from
Dec 4, 2017

Conversation

garrettmoon
Copy link
Member

No description provided.

@ghost
Copy link

ghost commented Oct 23, 2017

🚫 CI failed with log

Copy link
Member

@nguyenhuy nguyenhuy left a comment

Choose a reason for hiding this comment

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

Nice improvements overall!

@@ -53,6 +53,14 @@ - (void)_locked_setAnimatedImage:(id <ASAnimatedImageProtocol>)animatedImage
if (ASObjectIsEqual(_animatedImage, animatedImage)) {
return;
}

if (animatedImage == nil) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this check. Shouldn't we do this whenever _animatedImage != nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeeeeees, good catch.

if (animatedImage == nil) {
// Animated image can take while to dealloc, do it off the main queue
__block id <ASAnimatedImageProtocol>deallocImage = _animatedImage;
ASPerformBlockOnBackgroundThread(^{
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, let's use ASPerformBackgroundDeallocation(). Also, let's use previousAnimatedImage declared a few lines below.

Copy link
Member

Choose a reason for hiding this comment

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

Lastly, I think it's easier to reason if we do this at the end of this method.

if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
return;
}
ASPerformBlockOnBackgroundThread(^{
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm, the only change here is that the (previous) finished block is now executed on a background thread? (it's a bit hard to read)

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly. Everything before was happening on main. Now it's being dispatched to the background and once it's done the work, the delegate callbacks are dispatched to main.

@nguyenhuy
Copy link
Member

@garrettmoon There are conflicts that I'm not confident in fixing. Please resolve them and merge away.

Copy link
Contributor

@maicki maicki left a comment

Choose a reason for hiding this comment

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

LGTM


if (imageContainer != nil) {
[strongSelf _locked_setCurrentImageQuality:1.0];
if ([imageContainer asdk_animatedImageData] && strongSelf->_downloaderFlags.downloaderImplementsAnimatedImage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could move up calling asdk_animatedImageData and assign it to a variable so you don't have to call it twice if this evaluates to true. Don't know how heavy asdk_animatedImageData is though.

@nguyenhuy
Copy link
Member

@garrettmoon Ping :)

@garrettmoon
Copy link
Member Author

@nguyenhuy Ah! Will resolve and land today, thank you all for the review!

@ghost
Copy link

ghost commented Dec 4, 2017

🚫 CI failed with log

@garrettmoon garrettmoon changed the title A couple performance tweaks for animated images A couple performance tweaks for animated images #trivial Dec 4, 2017
Copy link
Member

@Adlai-Holler Adlai-Holler left a comment

Choose a reason for hiding this comment

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

One issue

if (previousAnimatedImage != nil) {
ASPerformBackgroundDeallocation(&previousAnimatedImage);
}

[self animatedImageSet:_animatedImage previousAnimatedImage:previousAnimatedImage];
Copy link
Member

Choose a reason for hiding this comment

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

previousAnimatedImage will be nilled out by this function. Call this after calling -animatedImageSet:previousAnimatedImage:

Copy link
Member Author

Choose a reason for hiding this comment

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

Oooh, good catch!

Copy link
Member

@Adlai-Holler Adlai-Holler left a comment

Choose a reason for hiding this comment

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

lgtm

@garrettmoon garrettmoon merged commit 0b6d41f into master Dec 4, 2017
@Adlai-Holler Adlai-Holler deleted the animatedImagePerformanceTweaks branch January 31, 2018 16:11
bernieperez pushed a commit to AtomTickets/Texture that referenced this pull request Apr 25, 2018
…p#634)

* A couple performance tweaks for animated images

* @nguyenhuy's comments

* Avoid calling animatedImageData twice. Thanks @maicki.

* Fix call to background deallocation

* Good catch by @Adlai-Holler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants