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
Figure out an approach to NodePath 'hub' object tracking with better cache behavior #6437
Labels
i: bug
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
pkg: traverse
Milestone
Comments
Would making get hub() {
return this
_hub || (this.parentPath && this.parentPath.hub);
} |
xtuc
added
the
PR: Internal 🏠
A type of pull request used for our changelog categories
label
Oct 9, 2017
liuxingbaoyu
added
pkg: traverse
and removed
PR: Internal 🏠
A type of pull request used for our changelog categories
labels
Oct 17, 2022
robhogan
added a commit
to robhogan/metro
that referenced
this issue
Dec 17, 2022
…nMap` Summary: ## Motivation For performance reasons, we'd like to have the option to re-use an AST (without cloning) after deriving source map information from it. However, due to babel/babel#6437, traversing the AST within `generateFunctionMap` causes the `babel/traverse` path cache to be populated with entries Babel transform plugins can't use - in particular because `hub` is assumed to be set. ## Change This diffs saves and clears the traverse cache before traversal, and then restores it afterwards. This isn't pretty but it's the cleanest approach I could find - we include tests to verify that this is (and continues to be) necessary. ## Other approaches I tried some other things before resorting to manipulating `babel/traverse` internals: - Actually providing a `hub` so that it's set on the cache means adding a dependency on `babel/core`, and requires a similar level of hackery / assumptions of Babel internals. - Clearing the bad cache with `traverse.clearNode(ast)` or `traverse.cache.clearPath()` doesn't work because other tools (eg, Jest) rely on `properties` held in the path cache. Changelog: [Internal] Differential Revision: D42068914 fbshipit-source-id: f473f67f17ffe92c9fc378ef54f3dc40bcf25f7a
facebook-github-bot
pushed a commit
to facebook/metro
that referenced
this issue
Dec 19, 2022
…nMap` (#906) Summary: Pull Request resolved: #906 ## Motivation For performance reasons, we'd like to have the option to re-use an AST (without cloning) after deriving source map information from it. However, due to babel/babel#6437, traversing the AST within `generateFunctionMap` causes the `babel/traverse` path cache to be populated with entries Babel transform plugins can't use - in particular because `hub` is assumed to be set. ## Change This diffs saves and clears the traverse cache before traversal, and then restores it afterwards. This isn't pretty but it's the cleanest approach I could find - we include tests to verify that this is (and continues to be) necessary. ## Other approaches I tried some other things before resorting to manipulating `babel/traverse` internals: - Actually providing a `hub` so that it's set on the cache means adding a dependency on `babel/core`, and requires a similar level of hackery / assumptions of Babel internals. - Clearing the bad cache with `traverse.clearNode(ast)` or `traverse.cache.clearPath()` doesn't work because other tools (eg, Jest) rely on `properties` held in the path cache. Changelog: [Internal] Reviewed By: jacdebug, motiz88 Differential Revision: D42068914 fbshipit-source-id: e928b7ee1ffc5462f0ead7bcf4077b818a4cd95a
I'm investigating this |
#12570 |
github-actions
bot
added
the
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
label
Nov 2, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
i: bug
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
pkg: traverse
I recently realized we've got bug with our invalidation logic for NodePath that can cause some real weirdness. Here it is on ASTExplorer and here:
will print
undefined
forhub
even throughp2.hub
is theHub
class instance.Which is surprising because in
babel/packages/babel-traverse/src/path/index.js
Line 74 in d511cfc
hub
value is explicitly supposed to pass down.It fails in this case because on
babel/packages/babel-traverse/src/path/index.js
Line 91 in d511cfc
The problem is, what do we do. Two options come to mind:
.hub
on the cache result.Option 1
Pretty gross because we could just as easily be introducing another bug by removing a Hub instance that was supposed to be there
Option 2
Sounds reasonable, until you realize that we actually crucially rely on this gross caching behavior to instantiate
NodePath
with the correctHub
instance in the first place.In
File
init inbabel/packages/babel-core/src/transformation/file/file.js
Line 42 in d511cfc
NodePath
, but then we never really do anything with it. Traversal begins onbabel/packages/babel-core/src/transformation/index.js
Line 71 in d511cfc
this.path
at all. That path ends up being used, thus using the rootHub
, because it is present in the cache. If we explicitly test for theHub
in the cache, we'll break this weird cache-based pass-through logic.Solution?
To me, the "feature" we're breaking in option 2 is totally a mistake to rely on since it is essentially relying on sideeffects to the extreme. This means we need a way to do two things:
File
class instanceThe exact details on how we do those two things is up in the air, but feels like something we should figure out ASAP.
Incidentally, this same bug is the reason we have to do
babel/packages/babel-template/src/index.js
Line 218 in d511cfc
babel-template
would trigger this bug, due to the internal traversal, which doesn't have ahub
, polluting the cache.The text was updated successfully, but these errors were encountered: