Skip to content

Commit 84956a2

Browse files
guybedfordarv
authored andcommitted
implement bulk re-exports for instantiate setter perf
1 parent 1f982c0 commit 84956a2

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/codegeneration/InstantiateModuleTransformer.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,29 +349,31 @@ export class InstantiateModuleTransformer extends ModuleTransformer {
349349

350350
// then do export bindings of re-exported dependencies
351351
if (externalExportBindings) {
352+
let reexports = Object.create(null);
352353
externalExportBindings.forEach(({exportName, importName}) => {
353-
let statement = importName === null ?
354-
parseStatement `$__export(${exportName}, $__m);` :
355-
parseStatement `$__export(${exportName}, $__m.${importName});`;
356-
setterStatements.push(statement);
354+
reexports[exportName] = importName === null ?
355+
parseExpression `$__m` : parseExpression `$__m.${importName}`;
357356
});
357+
setterStatements.push(
358+
parseStatement `$__export(${createObjectLiteral(reexports)})`);
358359
}
359360

360361
// create local module bindings
361362
if (moduleBinding) {
362363
setterStatements.push(
363-
parseStatement `${id(moduleBinding)} = $__m;`
364-
);
364+
parseStatement `${id(moduleBinding)} = $__m;`);
365365
}
366366

367367
// finally run export * if applying to this dependency, for not-already
368368
// exported dependencies
369369
if (exportStarBinding) {
370370
setterStatements = setterStatements.concat(parseStatements `
371+
var exportObj = Object.create(null);
371372
Object.keys($__m).forEach(function(p) {
372373
if (p !== 'default' && !$__exportNames[p])
373-
$__export(p, $__m[p]);
374+
exportObj[p] = $__m[p];
374375
});
376+
$__export(exportObj);
375377
`);
376378

377379
let exportNames = {};

third_party/es6-module-loader/loader.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,16 @@ function logloads(loads) {
687687
// NB This should be an Object.defineProperty, but that is very slow.
688688
// By disaling this module write-protection we gain performance.
689689
// It could be useful to allow an option to enable or disable this.
690-
moduleObj[name] = value;
690+
691+
// bulk export object
692+
if (typeof name == 'object') {
693+
for (var p in name)
694+
moduleObj[p] = name[p];
695+
}
696+
// single export name / value pair
697+
else {
698+
moduleObj[name] = value;
699+
}
691700

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

0 commit comments

Comments
 (0)