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

Add a way to opt out of always-clear-data behavior in ASCollectionView and ASTableView #1284

Merged
merged 5 commits into from
Dec 20, 2018

Conversation

nguyenhuy
Copy link
Member

@nguyenhuy nguyenhuy commented Dec 14, 2018

Through crashes in the past, we established that:

  1. We can't clear data if the collection/table view is still being used. (Clearing data frequently while delegate / dataSource is changing within collection view can cause crashes #1155)
  2. We may clear data during deallocation, and even so, we want to do it if user is in ASExperimentalClearDataDuringDeallocation experiment.

As such, the logic change introduced in #1200 is not correct. It causes -clearData to always be executed if user is not in the experiment (which is true by default).

screen shot 2018-12-13 at 9 41 24 pm

I suspect what you wanted to do is setting up an experiment and hook up with Texture. And even then, we need to fix the implementation of clearData. I'm seeing a crash in production (1st screenshot below) which looks like a memory issue when self (i.e the collection view) is gone and accessing the editing queue (i.e self->_editingTransactionGroup) after that is problematic (see 2nd screenshot).

screen shot 2018-12-13 at 10 16 37 pm

screen shot 2018-12-13 at 10 08 15 pm

I think clearData needs to avoid calling -waitUntilAllUpdatesAreProcessed altogether. Instead, it needs to:

  1. Destroy the editing queue.
  2. Destroy the main serial queue.
  3. Clear out the visible and pending maps.

@maicki
Copy link
Contributor

maicki commented Dec 14, 2018

I don't think this is the right logic either as it would change the initial behavior. In this case we would have to enable the ASExperimentalClearDataDuringDeallocation experimental feature to get the initial behavior we had in the first place, calling [_dataController clearData]; every time. Furthermore it would not reflect the initial behavior we had as it is checking _isDeallocating before clearing.

I would suggest we add an overall experimental feature and change the logic to something like this:

if (_asyncDataSource == nil && _asyncDelegate == nil) {
    // Overall experiment to test if different clearing behaviors will fix some issues
    if (ASActivateExperimentalFeature(ASExperimentalTestClearDuringDeallocation)) {
        // If this experiment is activated we only clear if _isDeallocating == TRUE
        if (ASActivateExperimentalFeature(ASExperimentalClearDataDuringDeallocation)) {
            if (_isDeallocating) {
                [_dataController clearData];          
            }
        // Here is room for some other cases we would like to test
        } else {
            // In this case we would not clear at all
        }
    } else {
        // Default behavior as before
        [_dataController clearData];  
    }
}

@nguyenhuy
Copy link
Member Author

nguyenhuy commented Dec 14, 2018

The thing is we don’t want to keep the original behavior (i.e always call clearData). The implementation of clearData is problematic, both while the collection view is being used and when it’s being deallocated.

In this case we would have to enable the ASExperimentalClearDataDuringDeallocation experimental feature to get the initial behavior we had in the first place

That is intended as I understand it helps to workaround the root cause. It's an opt-in workaround.

However, the implementation in #1200 and the one you proposed here doesn't give us an easy option to opt-out of the initial behavior which has been causing crashes.

@nguyenhuy
Copy link
Member Author

Ok, I've just updated the logic to check the experiment first. It means you'll have room to test other cases in which clearing data is needed. I still think it should be opt-in as we don't want to keep the original problematic behavior.

@ghost
Copy link

ghost commented Dec 14, 2018

🚫 CI failed with log

@maicki
Copy link
Contributor

maicki commented Dec 17, 2018

@nguyenhuy Would be great to have this PR not change the standard behavior where it clears by default. Applications still rely on this behavior and we can not make it opt in. We should make the new behavior (clear only on deallocation) opt in it until all bigger clients of Texture can agree what the final behavior we should strive for.

@nguyenhuy
Copy link
Member Author

@maicki I updated the diff to always clear data (the original behavior) unless a client explicitly opts out (and Pinterest is going to). This essentially reverts all recent changes to get us back to #1136. LGTY?

@nguyenhuy nguyenhuy changed the title Fix logic in ASCollectionView and ASTableView to only clear data during deallocation and in the experiment Fix logic in ASCollectionView and ASTableView to always clear data unless a client explicitly opts out Dec 20, 2018
@nguyenhuy nguyenhuy changed the title Fix logic in ASCollectionView and ASTableView to always clear data unless a client explicitly opts out Add a way to opt out of always-clear-data behavior in ASCollectionView and ASTableView Dec 20, 2018
@nguyenhuy nguyenhuy merged commit 17e5604 into TextureGroup:master Dec 20, 2018
@TextureGroup TextureGroup deleted a comment Dec 20, 2018
@TextureGroup TextureGroup deleted a comment Dec 20, 2018
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

2 participants