serializer.unstable_inlineDependencyMap: Add opt-in serialise-time module id inlining to the serialiser (#1786) - #1786
Closed
robhogan wants to merge 2 commits into
Closed
serializer.unstable_inlineDependencyMap: Add opt-in serialise-time module id inlining to the serialiser (#1786)#1786robhogan wants to merge 2 commits into
robhogan wants to merge 2 commits into
Conversation
Contributor
|
@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112353887. |
…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
Bot
force-pushed
the
export-D112353887
branch
from
July 23, 2026 12:41
573a437 to
d1bc7f2
Compare
Contributor
|
This pull request has been merged in d137ec4. |
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:
Wires the
inlineModuleIdReferenceshelper (previous diff) into the OSS serialiser behind a new opt-inserializer.unstable_inlineDependencyMap, porting this Metro-Buck optimisation to core.When
serializer.unstable_inlineDependencyMapANDtransformer.unstable_dependencyMapReservedNameis 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
nullkeeps that slot occupied so the verbose-name argument stays in position.With the flag off, output is unchanged.
Threading:
SerializerConfigT(+ default) gainsunstable_inlineDependencyMap.SerializerOptionsgains optionalunstable_inlineDependencyMapanddependencyMapReservedName.Server.jspopulates both at all three serialiser-options construction sites from resolved config (the reserved name is already resolved at serialise time).baseJSBundle->processModules->wrapModule/getModuleParamsthread the options.Changelog:
Reviewed By: motiz88, huntie
Differential Revision: D112353887