Skip to content

Commit

Permalink
Free modules' factories after caching module
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tadeuzagallo authored and Facebook Github Bot 5 committed Apr 19, 2016
1 parent 551c154 commit 887c275
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packager/react-packager/src/Resolver/polyfills/require-unbundle.js
@@ -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;
Expand Down Expand Up @@ -67,6 +76,7 @@ function loadModuleImplementation(moduleId, module) {

const moduleObject = {exports};
factory(global, require, moduleObject, exports);
module.factory = undefined;

if (__DEV__) {
Systrace.endEvent();
Expand Down
12 changes: 11 additions & 1 deletion packager/react-packager/src/Resolver/polyfills/require.js
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 887c275

Please sign in to comment.