Skip to content

serializer.unstable_inlineDependencyMap: Add opt-in serialise-time module id inlining to the serialiser (#1786) - #1786

Closed
robhogan wants to merge 2 commits into
mainfrom
export-D112353887
Closed

serializer.unstable_inlineDependencyMap: Add opt-in serialise-time module id inlining to the serialiser (#1786)#1786
robhogan wants to merge 2 commits into
mainfrom
export-D112353887

Conversation

@robhogan

@robhogan robhogan commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary:

Wires the inlineModuleIdReferences helper (previous diff) into the OSS serialiser behind a new opt-in serializer.unstable_inlineDependencyMap, porting this Metro-Buck optimisation to core.

When serializer.unstable_inlineDependencyMap AND transformer.unstable_dependencyMapReservedName is set, each module body has its <reservedName>[i] references replaced with the resolved numeric module ID (right-padded to preserve source-map columns), and the dependency-map array argument is dropped from the __d(...) call (where it is empty AND the last argument).

For dev bundles, a null keeps that slot occupied so the verbose-name argument stays in position.

With the flag off, output is unchanged.

Threading:

  • SerializerConfigT (+ default) gains unstable_inlineDependencyMap.
  • SerializerOptions gains optional unstable_inlineDependencyMap and dependencyMapReservedName.
  • Server.js populates both at all three serialiser-options construction sites from resolved config (the reserved name is already resolved at serialise time).
  • baseJSBundle -> processModules -> wrapModule/getModuleParams thread the options.

Changelog:

 - **[Experimental]**: Add `serializer.unstable_inlineDependencyMap` for an opt-in runtime optimisation.

Reviewed By: motiz88, huntie

Differential Revision: D112353887

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 22, 2026
@meta-codesync

meta-codesync Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112353887.

robhogan added 2 commits July 23, 2026 05:40
…g helper

Summary:
Upstream `inlineModuleIdReferences`, a pure string helper, from Metro-Buck to the OSS serialiser. This utility replaces `dependencyMapReservedName[i]` references in a module body with the resolved numeric module ID of dependency `i`, without any reparse or AST manipulation, with padding to preserve source map correctness.

The safety of pure string replacement is guaranteed by `unstable_dependencyMapReservedName` (optional, enforces that that string cannot appear in user code) - this utility will throw if that's not set.

In Metro-Buck, this powers an a runtime optimisation that replaces an array access with the literal. Immediately, this saves a bunch of array accesses during startup (especially if `inlineRequires` is disabled), and provides a modest bundle size reduction. On top of that, it unlocks `$SHBuiltin`-based optimisations (`unstable_enableStaticHermesOptimizedRequire`), which currently rely on matching a `require(<literal>)`.

The OSS serialiser itself is not yet wired to use the helper; that opt-in wiring lands in the next diff.

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D112353888
…dule id inlining to the serialiser (#1786)

Summary:

Wires the `inlineModuleIdReferences` helper (previous diff) into the OSS serialiser behind a new opt-in `serializer.unstable_inlineDependencyMap`, porting this Metro-Buck optimisation to core.

When `serializer.unstable_inlineDependencyMap` AND `transformer.unstable_dependencyMapReservedName` is set, each module body has its `<reservedName>[i]` references replaced with the resolved numeric module ID (right-padded to preserve source-map columns), and the dependency-map array argument is dropped from the `__d(...)` call (where it is empty AND the last argument).

For dev bundles, a `null` keeps that slot occupied so the verbose-name argument stays in position.

With the flag off, output is unchanged.

Threading:
- `SerializerConfigT` (+ default) gains `unstable_inlineDependencyMap`.
- `SerializerOptions` gains optional `unstable_inlineDependencyMap` and `dependencyMapReservedName`.
- `Server.js` populates both at all three serialiser-options construction sites from resolved config (the reserved name is already resolved at serialise time).
- `baseJSBundle` -> `processModules` -> `wrapModule`/`getModuleParams` thread the options.

Changelog:
```
 - **[Experimental]**: Add `serializer.unstable_inlineDependencyMap` for an opt-in runtime optimisation.
```

Reviewed By: motiz88, huntie

Differential Revision: D112353887
@meta-codesync meta-codesync Bot changed the title serializer.unstable_inlineDependencyMap: Add opt-in serialise-time module id inlining to the serialiser serializer.unstable_inlineDependencyMap: Add opt-in serialise-time module id inlining to the serialiser (#1786) Jul 23, 2026
@meta-codesync
meta-codesync Bot force-pushed the export-D112353887 branch from 573a437 to d1bc7f2 Compare July 23, 2026 12:41
@meta-codesync meta-codesync Bot closed this in d137ec4 Jul 23, 2026
@meta-codesync meta-codesync Bot added the Merged label Jul 23, 2026
@meta-codesync

meta-codesync Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in d137ec4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant