Skip to content

Implement bulk re-exports for instantiate setter perf #1957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/codegeneration/InstantiateModuleTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,29 +349,31 @@ export class InstantiateModuleTransformer extends ModuleTransformer {

// then do export bindings of re-exported dependencies
if (externalExportBindings) {
let reexports = Object.create(null);
externalExportBindings.forEach(({exportName, importName}) => {
let statement = importName === null ?
parseStatement `$__export(${exportName}, $__m);` :
parseStatement `$__export(${exportName}, $__m.${importName});`;
setterStatements.push(statement);
reexports[exportName] = importName === null ?
parseExpression `$__m` : parseExpression `$__m.${importName}`;
});
setterStatements.push(
parseStatement `$__export(${createObjectLiteral(reexports)})`);
}

// create local module bindings
if (moduleBinding) {
setterStatements.push(
parseStatement `${id(moduleBinding)} = $__m;`
);
parseStatement `${id(moduleBinding)} = $__m;`);
}

// finally run export * if applying to this dependency, for not-already
// exported dependencies
if (exportStarBinding) {
setterStatements = setterStatements.concat(parseStatements `
var exportObj = Object.create(null);
Object.keys($__m).forEach(function(p) {
if (p !== 'default' && !$__exportNames[p])
$__export(p, $__m[p]);
exportObj[p] = $__m[p];
});
$__export(exportObj);
`);

let exportNames = {};
Expand Down
11 changes: 10 additions & 1 deletion third_party/es6-module-loader/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,16 @@ function logloads(loads) {
// NB This should be an Object.defineProperty, but that is very slow.
// By disaling this module write-protection we gain performance.
// It could be useful to allow an option to enable or disable this.
moduleObj[name] = value;

// bulk export object
if (typeof name == 'object') {
for (var p in name)
moduleObj[p] = name[p];
}
// single export name / value pair
else {
moduleObj[name] = value;
}

for (var i = 0, l = module.importers.length; i < l; i++) {
var importerModule = module.importers[i];
Expand Down