Skip to content

Commit

Permalink
perf: prefer using Date.now() (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jul 7, 2024
1 parent 43db5f1 commit ea5d160
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/cached-child-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class PersistentChildCompilerSingletonPlugin {
let mainCompilationHashOfLastChildRecompile = '';
/** @type {Snapshot | undefined} */
let previousFileSystemSnapshot;
let compilationStartTime = new Date().getTime();
let compilationStartTime = Date.now();

compiler.hooks.make.tapAsync(
'PersistentChildCompilerSingletonPlugin',
Expand All @@ -242,7 +242,7 @@ class PersistentChildCompilerSingletonPlugin {
}

// Update the time to the current compile start time
compilationStartTime = new Date().getTime();
compilationStartTime = Date.now();

// The compilation starts - adding new templates is now not possible anymore
this.compilationState = {
Expand Down
5 changes: 3 additions & 2 deletions lib/child-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class HtmlWebpackChildCompiler {
* @param {string[]} templates
*/
constructor (templates) {
console.log('create child compiler');
/**
* @type {string[]} templateIds
* The template array will allow us to keep track which input generated which output
Expand Down Expand Up @@ -125,7 +126,7 @@ class HtmlWebpackChildCompiler {
url: 'relative'
};

this.compilationStartedTimestamp = new Date().getTime();
this.compilationStartedTimestamp = Date.now();
/** @type {Promise<{[templatePath: string]: ChildCompilationTemplateResult}>} */
this.compilationPromise = new Promise((resolve, reject) => {
/** @type {Source[]} */
Expand Down Expand Up @@ -212,7 +213,7 @@ class HtmlWebpackChildCompiler {
};
});

this.compilationEndedTimestamp = new Date().getTime();
this.compilationEndedTimestamp = Date.now();

resolve(result);
});
Expand Down

0 comments on commit ea5d160

Please sign in to comment.