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 babel register cache invalidation #14303

Merged
merged 1 commit into from Feb 24, 2022
Merged

Conversation

cha0s
Copy link
Contributor

@cha0s cha0s commented Feb 24, 2022

Incredibly, @babel/register wasn't caching anything. This is because setDirty() must be called on the worker cache, otherwise the check at https://github.com/babel/babel/blob/main/packages/babel-register/src/worker/cache.js#L32 always fails.

I couldn't believe it when I started digging into why caching seemed to do nothing. Lazy! ;)

Q                       A
Fixed Issues? Shockingly, no one seems to have noticed until now?
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? No
License MIT

Incredibly, @babel/register wasn't caching anything. This is because `setDirty()` must be called on the worker cache, otherwise the check at https://github.com/babel/babel/blob/main/packages/babel-register/src/worker/cache.js#L32 always fails.

I couldn't believe it when I started digging into why caching seemed to do nothing. Lazy! ;)
@babel-bot
Copy link
Collaborator

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

@cha0s
Copy link
Contributor Author

cha0s commented Feb 24, 2022

Figured I'd attach a patch-package patch here for anyone following along:

diff --git a/node_modules/@babel/register/lib/worker/transform.js b/node_modules/@babel/register/lib/worker/transform.js
index 8a1cef0..c30688d 100644
--- a/node_modules/@babel/register/lib/worker/transform.js
+++ b/node_modules/@babel/register/lib/worker/transform.js
@@ -137,6 +137,7 @@ function cacheLookup(opts, filename) {
         value,
         mtime: fileMtime
       };
+      registerCache.setDirty();
       return value;
     }

My build time halved in the moderately-sized project that I've tested so far.

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.

Whops, thanks!

@existentialism existentialism added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: register labels Feb 24, 2022
@existentialism existentialism merged commit 7686fc0 into babel:main Feb 24, 2022
@nicolo-ribaudo nicolo-ribaudo changed the title fix: cache Fix babel register cache invalidation Feb 24, 2022
@cha0s cha0s deleted the patch-1 branch February 27, 2022 12:19
@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 May 30, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: register PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants