Move preloaded modules to startup code section

Summary:We found that moving the preloaded modules to the startup section of the RAM Bundle improves TTI quite a bit by saving lots of through the bridge calls and injecting multiple modules at once on JSC. However, doing this on a non hacky way required a lot of work. The main changes this diff does are:
  - Add to `BundleBase` additional bundling options. This options are fetched based on the entry file we're building by invoking a module that exports a function (`getBundleOptionsModulePath`).
  - Implement `BundleOptions` module to include the `numPreloadedModules` attribute as a bundle additional option. This value is computed by getting the dependencies the entry file has and looking for the first module that exports a module we don't want to preload. The `numPreloadedModules` attribute is then used to decide where to splice the array of modules.
- Additional kung fu to make sure sourcemaps work for both preloaded and non preloaded modules.

Reviewed By: davidaurelio

Differential Revision: D3046534

fb-gh-sync-id: 80b676222ca3bb8b9eecc912a7963be94d3dee1a
shipit-source-id: 80b676222ca3bb8b9eecc912a7963be94d3dee1a
This commit is contained in:
Martín Bigio
2016-03-23 09:27:19 -07:00
committed by Facebook Github Bot 1
parent 7be18819ec
commit 8edc35004c
9 changed files with 96 additions and 35 deletions

View File

@@ -34,7 +34,7 @@ function saveAsAssets(bundle, options, log) {
} = options;
log('start');
const {startupCode, startupModules, modules} = bundle.getUnbundle();
const {startupCode, startupModules, modules} = bundle.getUnbundle('ASSETS');
log('finish');
log('Writing bundle output to:', bundleOutput);

View File

@@ -31,7 +31,7 @@ function saveAsIndexedFile(bundle, options, log) {
} = options;
log('start');
const {startupCode, modules} = bundle.getUnbundle();
const {startupCode, modules} = bundle.getUnbundle('INDEX');
log('finish');
log('Writing unbundle output to:', bundleOutput);
@@ -112,7 +112,7 @@ function buildModuleTable(buffers) {
uInt32Buffer(currentLine),
]);
currentLine += linesCount - 1;
currentLine += linesCount;
currentOffset += length;
tableLength += entry.length;
@@ -129,7 +129,7 @@ function buildModuleBuffers(startupCode, modules, encoding) {
modules.map(module =>
moduleToBuffer(
String(module.id),
module.code + '\n', // each module starts on a newline
module.code,
encoding,
)
)

View File

@@ -24,12 +24,9 @@ const SourceMapConsumer = sourceMap.SourceMapConsumer;
*/
function buildUnbundleSourcemap(bundle) {
const generator = new sourceMap.SourceMapGenerator({});
const nonPolyfillModules = bundle.getModules().filter(module =>
!module.polyfill
);
let offset = 1;
nonPolyfillModules.forEach(module => {
let offset = 0;
bundle.getUnbundle('INDEX').allModules.forEach(module => {
if (module.map) { // assets have no sourcemap
const consumer = new SourceMapConsumer(module.map);
consumer.eachMapping(mapping => {