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

[ASDisplayNode] Convert isSynchronous to an Objective-C atomic BOOL. #88

Closed
wants to merge 1 commit into from

Conversation

appleguy
Copy link
Member

This reduces lock contention, and should also fix a very rarely seen deadlock.

See #64 for details.

@Adlai-Holler -- this is a case where I think a std::atomic would probably be better if we had a convenient access pattern. If we carried this pattern to other flags, the message send overhead would definitely become significant.

Although it's in the margin (most apps spend between 8-13% of all CPU time in objc_msgSend), for a core library it's great to keep that overhead as low as practical; BOOL flags seem like a possible opportunity to do something really efficient.

I'm also wondering if we could use a bitfield or something else more packed. It's not an issue for one BOOL, but I bet we'd get significant gains out of moving all the _flags to std::atomic bitfields if they were kept within 32 bits per field. We'd be able to avoid locking the mutex in many situations we do today, which would help not just CPU time but also contention / scheduler waiting.

This reduces lock contention, and should also fix a very rarely seen deadlock.
@appleguy appleguy self-assigned this Apr 30, 2017
@ghost
Copy link

ghost commented Apr 30, 2017

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

Generated by 🚫 Danger

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.

Great! Let's standardize on using property names, instead of accessor names, with dot syntax, so self.isSynchronous -> self.synchronous OR [self isSynchronous].

@appleguy
Copy link
Member Author

Here's a very rough cut at what a better _atomicFlags setup might look like:

https://gist.github.com/appleguy/9b7c325b1678d27312f33abaea21d2ce

@appleguy
Copy link
Member Author

Closing in favor of #89

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.

2 participants