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

Restore checking shadow tree commit cancellation after commit hook execution #38715

Conversation

michalmaka
Copy link
Contributor

Summary:

Hello! This PR is a fix for one merged some time ago (#36216). In the PR check for nullptr value of newRootShadowNode just after performing commit hooks was overlooked. This PR restores previous behaviour of conditional commit cancellation after commit hook execution.

Changelog:

[INTERNAL] [FIXED] - Restore checking shadow tree commit cancellation after commit hook execution

Test Plan:

Just register a commit hook that return nullptr. In that case current code crashes due to nullptr dereference.

@facebook-github-bot
Copy link
Contributor

Hi @michalmaka!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@analysis-bot
Copy link

analysis-bot commented Aug 1, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,890,133 +25
android hermes armeabi-v7a 7,938,157 +39
android hermes x86 9,287,837 +68
android hermes x86_64 9,189,460 +36
android jsc arm64-v8a 9,478,128 +41
android jsc armeabi-v7a 8,419,125 +41
android jsc x86 9,461,956 +66
android jsc x86_64 9,776,289 +29

Base commit: bfd5fe2
Branch: main

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Aug 1, 2023
@@ -374,11 +379,6 @@ CommitStatus ShadowTree::tryCommit(

auto newRevisionNumber = oldRevision.number + 1;

if (!newRootShadowNode ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's ok to remove the !newRootShadowNode check from here because we already checked it in the new block you added, but I think we should keep the rest. Layout is relatively slow so it could happen that the commit is requested to yield during layout, and we should still be able to cancel then. Changing this behavior without testing its impact would be risky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure thing.

By the way, what do you think about restoring that block with moving it just after getting a lock and before checking for revision numbers' mismatch? It may allow developers to cancel commit instead of getting failure on specific cases and shouldn't cause any behaviour changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed suggested changes, @rubennorte give me a shout about your opinion on that approach

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think that makes sense! thanks!

@facebook-github-bot
Copy link
Contributor

@ryancat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Aug 4, 2023
@facebook-github-bot
Copy link
Contributor

@ryancat merged this pull request in a30f393.

lunaleaps pushed a commit that referenced this pull request Aug 8, 2023
…ecution (#38715)

Summary:
Hello! This PR is a fix for one merged some time ago (#36216). In the PR check for `nullptr` value of `newRootShadowNode` just after performing commit hooks was overlooked. This PR restores previous behaviour of conditional commit cancellation after commit hook execution.

## Changelog:

[INTERNAL] [FIXED] - Restore checking shadow tree commit cancellation after commit hook execution

Pull Request resolved: #38715

Test Plan: Just register a commit hook that return `nullptr`. In that case current code crashes due to `nullptr` dereference.

Reviewed By: sammy-SC

Differential Revision: D47972245

Pulled By: ryancat

fbshipit-source-id: 7599ad11ed4b2dcaf25e53f676ec4530e37410d5
lunaleaps pushed a commit that referenced this pull request Aug 10, 2023
…ecution (#38715)

Summary:
Hello! This PR is a fix for one merged some time ago (#36216). In the PR check for `nullptr` value of `newRootShadowNode` just after performing commit hooks was overlooked. This PR restores previous behaviour of conditional commit cancellation after commit hook execution.

## Changelog:

[INTERNAL] [FIXED] - Restore checking shadow tree commit cancellation after commit hook execution

Pull Request resolved: #38715

Test Plan: Just register a commit hook that return `nullptr`. In that case current code crashes due to `nullptr` dereference.

Reviewed By: sammy-SC

Differential Revision: D47972245

Pulled By: ryancat

fbshipit-source-id: 7599ad11ed4b2dcaf25e53f676ec4530e37410d5
Kudo pushed a commit to expo/react-native that referenced this pull request Aug 21, 2023
…ecution (facebook#38715)

Summary:
Hello! This PR is a fix for one merged some time ago (facebook#36216). In the PR check for `nullptr` value of `newRootShadowNode` just after performing commit hooks was overlooked. This PR restores previous behaviour of conditional commit cancellation after commit hook execution.

## Changelog:

[INTERNAL] [FIXED] - Restore checking shadow tree commit cancellation after commit hook execution

Pull Request resolved: facebook#38715

Test Plan: Just register a commit hook that return `nullptr`. In that case current code crashes due to `nullptr` dereference.

Reviewed By: sammy-SC

Differential Revision: D47972245

Pulled By: ryancat

fbshipit-source-id: 7599ad11ed4b2dcaf25e53f676ec4530e37410d5
@michalmaka michalmaka deleted the fix/check-shadow-commit-hook-cancellation branch August 28, 2023 09:15
github-merge-queue bot pushed a commit to software-mansion/react-native-reanimated that referenced this pull request Aug 29, 2023
## Summary

During investigation of race between RN and reanimated shadow tree
committing I've noticed that if JS thread commits a new tree (triggering
`pleaseSkipReanimatedCommit`) after starting `commit` from reanimated,
the latter `commit` may cause JS commit failures.

What's more, additional calls to `shouldReanimatedSkipCommit ` result in
avoiding CPU consuming copy operations on nodes and thus seems to work
more performant.

I added those checks just before each operation handling and just after
full commit.

Chessboard example seemed to work a bit faster that without those
changes. I used also profiler and in overall CPU spends less time in
ShadowTree.

NOTICE ⚠️ 
This change requires change in RN codebase. PR has been submitted
facebook/react-native#38715

## Test plan

Check performance of e.g. chessboard example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants