Free modules' factories after caching module

Summary:The require functions will keep the generate bytecode + lexical environment in
memory unnecessarily, since we can be sure that it will be executed at most once

Reviewed By: davidaurelio

Differential Revision: D3168257

fb-gh-sync-id: 038e1bc08abea94ee52d0390b6aced5fb652f493
fbshipit-source-id: 038e1bc08abea94ee52d0390b6aced5fb652f493
This commit is contained in:
Tadeu Zagallo 2016-04-19 08:12:36 -07:00 committed by Facebook Github Bot 5
parent 551c154261
commit 887c275bcf
2 changed files with 21 additions and 1 deletions

View File

@ -1,3 +1,12 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
const {ErrorUtils, nativeRequire} = global;
@ -67,6 +76,7 @@ function loadModuleImplementation(moduleId, module) {
const moduleObject = {exports};
factory(global, require, moduleObject, exports);
module.factory = undefined;
if (__DEV__) {
Systrace.endEvent();

View File

@ -1,3 +1,12 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* eslint strict:0 */
var modules = Object.create(null);
var inGuard = false;
@ -36,7 +45,7 @@ function requireImpl(id) {
inGuard = true;
var returnValue;
try {
returnValue = requireImpl.apply(this, arguments);
returnValue = requireImpl(id);
} catch (e) {
global.ErrorUtils.reportFatalError(e);
}
@ -80,6 +89,7 @@ function requireImpl(id) {
// keep args in sync with with defineModuleCode in
// packager/react-packager/src/Resolver/index.js
mod.factory.call(global, global, require, mod.module, mod.module.exports);
mod.factory = undefined;
if (__DEV__) {
Systrace.endEvent();