Don't emit redundant empty arrays for modules with no dependencies (#1858) - #1858
Closed
robhogan wants to merge 1 commit into
Closed
Don't emit redundant empty arrays for modules with no dependencies (#1858)#1858robhogan wants to merge 1 commit into
robhogan wants to merge 1 commit into
Conversation
Contributor
|
@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113660291. |
…1858) Summary: ## Why? This is a small optimisation for runtime speed and bundle size that avoids allocating an empty array for an argument that is not referenced by the function (module) body. Metro-Buck already does this. This diff aligns Metro core and dev, which unblocks unforking the serialisers without introducing a regression. ## Why this is non-breaking By construction, an empty dependency map means the module has no collected dependencies, so the module body has no references to the dependency map *injected by Metro*. We must still ensure there are no references not injected by Metro. Two cases: - `transformer.unstable_dependencyMapReservedName` is set - in this case we enforce that there are no occurrences of the name (as a string) in the module body at all. - Above is not set (default). In that case we use `generateUid` when wrapping the module to ensure we pick a name that is not already bound (and note, this is after any user/framework-supplied transforms) In either case, the module body has no references to the argument. One caveat to mention is that the argument is technically accessible using the `arguments` array-like. This is definitely not considered part of the stable API of Metro. ## Note: Bundle analysers A category of potentially-affected consumers are those which statically analyse the bundle and might expect an array at the dependency map position. Even here, we should be safe because we already have certain module types with a simpler module wrapper - e.g. `wrapJson` never emits a dependency map. That said, heads up byCedric / Atlas. Changelog: Internal Reviewed By: huntie Differential Revision: D113660291
meta-codesync
Bot
force-pushed
the
export-D113660291
branch
from
August 12, 2026 15:32
1274f23 to
fdcb3f5
Compare
Contributor
|
This pull request has been merged in db49f2c. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Why?
This is a small optimisation for runtime speed and bundle size that avoids allocating an empty array for an argument that is not referenced by the function (module) body.
Metro-Buck already does this. This diff aligns Metro core and dev, which unblocks unforking the serialisers without introducing a regression.
Why this is non-breaking
By construction, an empty dependency map means the module has no collected dependencies, so the module body has no references to the dependency map injected by Metro.
We must still ensure there are no references not injected by Metro. Two cases:
transformer.unstable_dependencyMapReservedNameis set - in this case we enforce that there are no occurrences of the name (as a string) in the module body at all.generateUidwhen wrapping the module to ensure we pick a name that is not already bound (and note, this is after any user/framework-supplied transforms)In either case, the module body has no references to the argument.
One caveat to mention is that the argument is technically accessible using the
argumentsarray-like. This is definitely not considered part of the stable API of Metro.Note: Bundle analysers
A category of potentially-affected consumers are those which statically analyse the bundle and might expect an array at the dependency map position. Even here, we should be safe because we already have certain module types with a simpler module wrapper - e.g.
wrapJsonnever emits a dependency map. That said, heads up @byCedric / Atlas.Changelog: Internal
Reviewed By: huntie
Differential Revision: D113660291