Skip to content

Commit

Permalink
improve the time reported by the bundler (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper De Moor authored and devongovett committed May 11, 2018
1 parent db07fa5 commit 5962605
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Asset {
this.parentBundle = null;
this.bundles = new Set();
this.cacheData = {};
this.startTime = 0;
this.endTime = 0;
this.buildTime = 0;
this.bundledSize = 0;
}
Expand Down
15 changes: 11 additions & 4 deletions src/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,17 @@ class Bundle {

await packager.end();

this.bundleTime = Date.now() - startTime;
for (let asset of this.assets) {
this.bundleTime += asset.buildTime;
}
let assetArray = Array.from(this.assets);
let assetStartTime =
this.type === 'map'
? 0
: assetArray.sort((a, b) => a.startTime - b.startTime)[0].startTime;
let assetEndTime =
this.type === 'map'
? 0
: assetArray.sort((a, b) => b.endTime - a.endTime)[0].endTime;
let packagingTime = Date.now() - startTime;
this.bundleTime = assetEndTime - assetStartTime + packagingTime;
}

async _addDeps(asset, packager, included) {
Expand Down
5 changes: 3 additions & 2 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,16 @@ class Bundler extends EventEmitter {
asset.processed = true;

// First try the cache, otherwise load and compile in the background
let startTime = Date.now();
asset.startTime = Date.now();
let processed = this.cache && (await this.cache.read(asset.name));
let cacheMiss = false;
if (!processed || asset.shouldInvalidate(processed.cacheData)) {
processed = await this.farm.run(asset.name);
cacheMiss = true;
}

asset.buildTime = Date.now() - startTime;
asset.endTime = Date.now();
asset.buildTime = asset.endTime - asset.startTime;
asset.generated = processed.generated;
asset.hash = processed.hash;

Expand Down

0 comments on commit 5962605

Please sign in to comment.