[ASDisplayNode] Implement a std::atomic-based flag system for superb performance#89
Merged
Conversation
appleguy
commented
Apr 30, 2017
Member
This reduces lock contention, and should also fix a very rarely seen deadlock.
|
🚫 CI failed with log |
Adlai-Holler
requested changes
Apr 30, 2017
Adlai-Holler
left a comment
Member
There was a problem hiding this comment.
Nice! Left an idea to make it more scalable.
Member
There was a problem hiding this comment.
Let's remove this field until we use it.
Member
There was a problem hiding this comment.
Let's eliminate the flags argument from checkFlag and setFlag, and then remove the atomic_* macros.
Let's also have setFlag return the old value of the flag, so it would shake out like this:
#define checkFlag(flag) ((_atomicFlags.load() & flag) == flag)
// Returns the old value of the flag as a BOOL.
#define setFlag(flag, x) (((x ? _atomicFlags.fetch_or(flag) : _atomicFlags.fetch_and(~flag)) & flag) != 0)
// In code:
BOOL sync = checkFlag(ASDNFlagSynchronous);
setFlag(ASDNFlagSynchronous, YES);
Adlai-Holler
approved these changes
Apr 30, 2017
Adlai-Holler
left a comment
Member
There was a problem hiding this comment.
Alrighty! I'm down with this and we'll see how nice we can get the naming as we go.
…performance Although Objective-C atomics are equally fast, or better that std::atomic when access through method calls, for the most intense use cases it is best to avoid method calls entirely. In ASDisplayNode, we could benefit significantly from avoiding both method calls (already true today) but also avoid locking the mutex, for both CPU and contention gains. There will still be many methods that need locking for transactional consistency - however, there are currently dozens of accessor methods that could avoid frequent lock / unlock cycles with use of atomics, and other usages of the ivars directly where locking could be delayed until after early-return conditions are checked and passed.
Generated by 🚫 Danger |
Member
Author
|
Thanks for your help on this @Adlai-Holler ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.