Skip to content

Fix babel register cache invalidation#14303

Merged
existentialism merged 1 commit intobabel:mainfrom
cha0s:patch-1
Feb 24, 2022
Merged

Fix babel register cache invalidation#14303
existentialism merged 1 commit intobabel:mainfrom
cha0s:patch-1

Conversation

@cha0s
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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

@cha0s
Copy link
Copy Markdown
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
Copy Markdown
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.

4 participants