Skip to content

Commit

Permalink
Implement module-level memoization of inlined requires (#1346)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1346

A performance optimisation for `inlineRequries`, where we replace `const foo = require('./foo')` at top level with `var foo`, and replace subsequent references to `foo` with `(foo || foo = require('./foo')`.

This differs from plain `inlineRequires` by the use of the memo variable, which (for modules that don't return a falsy value) saves calling into `require`, backed by `metroRequire`, and retrieving the previously-initialised module from a `Map` by its numeric ID.

```
 - **[Experimental]:** Implement `transformer.unstable_memoizeInlineRequires` to optimise inlined access.
```

Reviewed By: javache

Differential Revision: D62125134

fbshipit-source-id: 1ddbd8051d4a00b0ec358be8838f43eb8b0144a0
  • Loading branch information
robhogan authored and facebook-github-bot committed Sep 6, 2024
1 parent 2c3a22a commit f35992c
Show file tree
Hide file tree
Showing 7 changed files with 572 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Object {
"unstable_dependencyMapReservedName": null,
"unstable_disableModuleWrapping": false,
"unstable_disableNormalizePseudoGlobals": false,
"unstable_memoizeInlineRequires": false,
"unstable_renameRequire": true,
"unstable_workerThreads": false,
"workerPath": "metro/src/DeltaBundler/Worker",
Expand Down Expand Up @@ -334,6 +335,7 @@ Object {
"unstable_dependencyMapReservedName": null,
"unstable_disableModuleWrapping": false,
"unstable_disableNormalizePseudoGlobals": false,
"unstable_memoizeInlineRequires": false,
"unstable_renameRequire": true,
"unstable_workerThreads": false,
"workerPath": "metro/src/DeltaBundler/Worker",
Expand Down Expand Up @@ -516,6 +518,7 @@ Object {
"unstable_dependencyMapReservedName": null,
"unstable_disableModuleWrapping": false,
"unstable_disableNormalizePseudoGlobals": false,
"unstable_memoizeInlineRequires": false,
"unstable_renameRequire": true,
"unstable_workerThreads": false,
"workerPath": "metro/src/DeltaBundler/Worker",
Expand Down Expand Up @@ -698,6 +701,7 @@ Object {
"unstable_dependencyMapReservedName": null,
"unstable_disableModuleWrapping": false,
"unstable_disableNormalizePseudoGlobals": false,
"unstable_memoizeInlineRequires": false,
"unstable_renameRequire": true,
"unstable_workerThreads": false,
"workerPath": "metro/src/DeltaBundler/Worker",
Expand Down
1 change: 1 addition & 0 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
unstable_disableNormalizePseudoGlobals: false,
unstable_renameRequire: true,
unstable_compactOutput: false,
unstable_memoizeInlineRequires: false,
unstable_workerThreads: false,
},
watcher: {
Expand Down
Loading

0 comments on commit f35992c

Please sign in to comment.