Search code examples
react-nativemetro-bundler

Significance of --indexed-ram-bundle for React Native bundling


Recently I've started using RAM bundles with inline requires to achieve better performance for React Native startup. To do so I've pretty much just followed an official guide. It works fine, but in the Android part of the guide they say:

Use the following lines on Android if you want to use a single indexed file:

project.ext.react = [
  bundleCommand: "ram-bundle",
  extraPackagerArgs: ["--indexed-ram-bundle"]
]

What is the significance of --indexed-ram-bundle? Why would I want to, or not want to have a single indexed file?

I see that by default iOS appears to use a single indexed file, while Android will create a set of files.


Solution

  • While unable to determine with great detail why one would like to do --indexed-ram-bundle for Android the Metro documentation does provide some information:

    Indexed RAM bundle

    This format composes the bundle as a binary file ... This structure is optimal for an environment that is able to load all code in memory at once ... This bundling is usually used by iOS.

    File RAM bundle

    Each module is stored as a file, with the name js-modules/${id}.js ... This bundling is usually used by Android, since package contents are zipped, and access to a zipped file is much faster. If the indexed format was used instead, all the bundled should be unzipped at once to get the code for the corresponding module.