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

Create a new dealloc queue that is more efficient #931

Merged
merged 9 commits into from
May 22, 2018

Conversation

Adlai-Holler
Copy link
Member

@Adlai-Holler Adlai-Holler commented May 22, 2018

The current dealloc queue has a number of issues:

  • It continues polling every 100ms, even when the app is in background or the phone is asleep.
    • May get the app suspended/terminated sooner.
  • It does an extra retain/release pair for each object when added. It copies the strong ref into the ivar, then releases original ref. Better would be to transfer the +1 into the ivar and skip both calls.
  • It occupies a thread that isn't needed.
  • It does an extra retain/release pair for each object during deallocation. It copies the strong ref into a local deque then releases the original ref, then releases the local ref.

This diff creates a new implementation ASDeallocQueueV2 that solves these issues and is also a lot easier to reason about. The experimental implementation is triggered by the new flag ASExperimentalDeallocQueue.

currentQueue.clear();
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

V1 is untouched except to remove the unused test_drain and _test_drain methods. The diff is hard to read in unified view =/

@TextureGroup TextureGroup deleted a comment May 22, 2018
@Adlai-Holler
Copy link
Member Author

CI is super flaky ……… seems like more fails than passes today. @garrettmoon is it worth like restarting the compy or something? That weird simulator bootstrap error =/

@TextureGroup TextureGroup deleted a comment May 22, 2018
@TextureGroup TextureGroup deleted a comment May 22, 2018
@TextureGroup TextureGroup deleted a comment May 22, 2018
@TextureGroup TextureGroup deleted a comment May 22, 2018
@Adlai-Holler Adlai-Holler requested a review from maicki May 22, 2018 15:00
NSParameterAssert(objectPtr != NULL);

// Cast to CFType so we can manipulate retain count manually.
auto cfPtr = (CFTypeRef *)(void *)objectPtr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we automatically get a +1 here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, ARC never touches CFTypeRefs, so the retain count of the object doesn't change anywhere in here. What happens is, we "steal" their +1 and set their pointer to nil. So now they can't see or release the object.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we had used (__bridge_retained CFTypeRef) then ARC would have added a +1.

_lock.lock();
auto isFirstEntry = _queue.empty();
// Push the pointer into our queue and clear their strong ref.
_queue.push_back(*cfPtr);

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same from above

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.

Very nice!

@Adlai-Holler Adlai-Holler merged commit 8b890f0 into master May 22, 2018
@Adlai-Holler Adlai-Holler deleted the AHDeallocQueueV2 branch May 22, 2018 16:06
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.

None yet

3 participants