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

Fix _guessExecutionStatusRelativeToDifferentFunctions perf #14617

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented May 30, 2022

Q                       A
Fixed Issues? Fixes #11693
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Accurately speaking, it will not hang infinitely, but it is extremely slow.
After applying this modification it will go from about 10 minutes to 100ms.

@liuxingbaoyu liuxingbaoyu added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: traverse i: regression labels May 30, 2022
@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52074/

@nicolo-ribaudo
Copy link
Member

Is it possible to write an unit test for this fix?

@liuxingbaoyu
Copy link
Member Author

It's kind of hard, I've tried stripping down the reproducible code and it still ends up being over 2000 lines.
Also it seems that light-jest-runner cannot handle timeouts.

Of course I can also add a test if you think it's needed.

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Nice work. This PR improves the _guessExecutionStatusRelativeToDifferentFunctions performance dramatically via dynamic programming. The execution status is cached so that when we don't have to descend into nodes when they are queried again by recursive calls.

@JLHwung JLHwung added PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories and removed PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Jun 7, 2022
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

I don't like that we have to manually maintain the executionStatusCache status (undefined vs inited), because it could be easily managed just relying on the call stack and passing the map as a parameter.

However, I don't see an easy way to do so without modifying exposed functions. We should refactor this in the future, maybe Babel 8.

@nicolo-ribaudo nicolo-ribaudo changed the title fix: path._guessExecutionStatusRelativeToDifferentFunctions Sometimes extremely slow Fix _guessExecutionStatusRelativeToDifferentFunctions perf Jun 8, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit f23d184 into babel:main Jun 8, 2022
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Babel traverse hangs on willIMaybeExecuteBefore after v7.6.0
4 participants