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

Clean Up ASDisplayLayer #trivial #315

Merged
merged 1 commit into from
May 29, 2017
Merged

Clean Up ASDisplayLayer #trivial #315

merged 1 commit into from
May 29, 2017

Conversation

Adlai-Holler
Copy link
Member

  • Make asyncDelegate an atomic property, rather than using a mutex.
    • The weird NS_VALID_UNTIL_END_OF_SCOPE code has been there since the original version of this file in 2014. Originally, the async delegate was accessed using a block, so I guess this was extra safety since they didn't know what you would do in the block. Anyway, ARC will retain the delegate throughout the method call so there's no behavior change here.
  • Make displaySuspended main-thread-only. This isn't actually a behavior/API change, since changing the value off-main in the past would trigger an assertion failure downstream (in -setNeedsDisplay or -cancelAsyncDisplay) anyway. Better to just bite the bullet.
  • Other miscellaneous cleanup.

@ghost
Copy link

ghost commented May 29, 2017

1 Warning
⚠️ Any source code changes should have an entry in CHANGELOG.md or have #trivial in their title.

Generated by 🚫 Danger

@Adlai-Holler Adlai-Holler changed the title Clean Up ASDisplayLayer Clean Up ASDisplayLayer #trivial May 29, 2017
Copy link
Member

@appleguy appleguy left a comment

Choose a reason for hiding this comment

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

These are some great improvements. Thanks @Adlai-Holler!

My preference would be to remove +defaultValueForKey and restore a two-line init method. You can decide and land either way.

@@ -179,13 +138,14 @@ + (id)defaultValueForKey:(NSString *)key
{
if ([key isEqualToString:@"displaysAsynchronously"]) {
return @YES;
} else if ([key isEqualToString:@"opaque"]) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not very familiar with the semantics of defaultValueForKey when used with standard layer properties like this. That said:

  • I think having the code in init is more visible for a user exploring where a potentially-unexpected default opacity is coming from.
  • This implementation will perform isEqualToString: on potentially thousands of accesses to unrelated properties. Although unlikely to be a focused performance hotspot, it probably would create distributed cost.
  • What do you think about removing this method entirely and setting both self.opaque = YES and self.displaysAsynchronously = YES in the init method?

Copy link
Member Author

@Adlai-Holler Adlai-Holler May 29, 2017

Choose a reason for hiding this comment

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

@appleguy In my testing, CA only queries this once per class and stores the result, and it also correctly handles overriding standard layer properties as far as I can tell. So the overall performance is probably better with this implementation, which for me overrides the point about a user understanding where an unexpected opacity came from. Thoughts?

@@ -209,7 +169,7 @@ - (void)display
ASDisplayNodeAssertMainThread();
[self _hackResetNeedsDisplay];
Copy link
Member

Choose a reason for hiding this comment

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

It's time to rename this method. YYAsyncLayer does the same thing :). Maybe just _clearNeedsDisplayFlag

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed but too lazy to do it now 😴

@Adlai-Holler
Copy link
Member Author

Since CA caches the default values, the current implementation should be faster than overriding init so I'll land this in its current state. We can always revise later.

@Adlai-Holler Adlai-Holler merged commit 7961aa9 into master May 29, 2017
@Adlai-Holler Adlai-Holler deleted the AHCleanupLayer branch May 29, 2017 22:38
bernieperez pushed a commit to AtomTickets/Texture that referenced this pull request Apr 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants