-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add webpack benchmark #8
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
const path = require("path"); | ||
|
||
module.exports = { | ||
rootDir: path.resolve(__dirname, "src"), | ||
transformIgnorePatterns: [ | ||
"/node_modules/", | ||
path.resolve(__dirname, "build") | ||
] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import b from "./b.js"; | ||
|
||
const message = import("./c.js").then(c => c.default + b); | ||
|
||
export default message; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 42; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "Hello world"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
watch: () => {} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
const eventLoop = require("./event-loop"); | ||
|
||
module.exports = task => { | ||
eventLoop.cancel(task); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// This is a very simple event loop implementation. It does not cover the exact behavior | ||
// in node, especially not the differences between process.nextTick and setImmediate. | ||
// It is, however, sufficient for the benchmark. | ||
const tasks = []; | ||
|
||
module.exports = { | ||
schedule(task) { | ||
tasks.push(task); | ||
}, | ||
cancel(task) { | ||
const i = tasks.indexOf(task); | ||
|
||
if (i > -1) { | ||
tasks.splice(i, 1); | ||
} | ||
}, | ||
run() { | ||
let task; | ||
while ((task = tasks.shift())) { | ||
task(); | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
const eventLoop = require("./event-loop"); | ||
|
||
exports.nextTick = function(fn) { | ||
const args = Array.prototype.slice.call(arguments, 1); | ||
eventLoop.schedule(() => { | ||
fn.apply(null, args); | ||
}); | ||
}; | ||
|
||
exports.platform = exports.arch = exports.execPath = exports.title = "browser"; | ||
exports.pid = 1; | ||
exports.browser = true; | ||
exports.env = {}; | ||
exports.argv = []; | ||
exports.cwd = () => "/"; | ||
exports.binding = name => { | ||
throw new Error("No such module. (Possibly not yet loaded)"); | ||
}; | ||
exports.exit = exports.kill = exports.umask = exports.dlopen = exports.uptime = exports.memoryUsage = exports.uvCounters = () => {}; | ||
exports.features = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
const eventLoop = require("./event-loop"); | ||
|
||
module.exports = function(fn) { | ||
const args = Array.prototype.slice.call(arguments, 1); | ||
const task = () => { | ||
fn.apply(null, args); | ||
}; | ||
eventLoop.schedule(task); | ||
return task; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,5 +79,18 @@ fs.writeFileSync( | |
"third_party/vue.runtime.esm-nobuble-2.4.4.js", | ||
require("raw-loader!../third_party/vue.runtime.esm-nobuble-2.4.4.js") | ||
); | ||
fs.mkdirpSync("/src/fixtures/webpack"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Webpack requires absolute file paths. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does that work when you run it via $ node src/cli |
||
fs.writeFileSync( | ||
"/src/fixtures/webpack/a.js", | ||
require("raw-loader!./fixtures/webpack/a.js") | ||
); | ||
fs.writeFileSync( | ||
"/src/fixtures/webpack/b.js", | ||
require("raw-loader!./fixtures/webpack/b.js") | ||
); | ||
fs.writeFileSync( | ||
"/src/fixtures/webpack/c.js", | ||
require("raw-loader!./fixtures/webpack/c.js") | ||
); | ||
|
||
module.exports = fs; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
const webpack = require("webpack"); | ||
const eventLoop = require("./mocks/event-loop"); | ||
|
||
const payloads = [ | ||
{ | ||
entry: "/src/fixtures/webpack/a.js" | ||
} | ||
].map(({ entry }, i) => ({ | ||
entry, | ||
output: { | ||
path: "/dist/webpack/", | ||
filename: `bundle.${i}.js` | ||
}, | ||
// Using bail option in order to receive noisy errors in the benchmark if something went wrong | ||
bail: true, | ||
// We need to define that because Firefox has a Object.prototype.watch function | ||
watch: false | ||
})); | ||
|
||
module.exports = { | ||
name: "webpack", | ||
fn() { | ||
payloads.forEach(config => { | ||
let finished = false; | ||
|
||
eventLoop.schedule(() => { | ||
const compiler = webpack(config); | ||
compiler.run((err, stats) => { | ||
if (err) { | ||
throw err; | ||
} | ||
if (stats.hasErrors()) { | ||
throw stats.compilation.errors[0]; | ||
} | ||
finished = true; | ||
}); | ||
}); | ||
eventLoop.run(); | ||
|
||
if (finished !== true) { | ||
throw new Error("Webpack did not finish synchronously"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure 😁 |
||
} | ||
}); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2017 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
const path = require("path"); | ||
const webpack = require("webpack"); | ||
const webpackConfig = require("../webpack.config.js"); | ||
|
||
const outputFile = path.resolve( | ||
__dirname, | ||
"..", | ||
"build", | ||
"webpack-benchmark.test.js" | ||
); | ||
let webpackBenchmark; | ||
|
||
beforeAll( | ||
() => | ||
new Promise((resolve, reject) => { | ||
const baseConfig = webpackConfig[0]; | ||
const config = Object.assign({}, baseConfig, { | ||
entry: require.resolve("./webpack-benchmark.js") | ||
}); | ||
config.output = Object.assign({}, baseConfig.output, { | ||
libraryTarget: "commonjs2", | ||
path: path.dirname(outputFile), | ||
filename: path.basename(outputFile) | ||
}); | ||
const compiler = webpack(config); | ||
compiler.run(err => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
webpackBenchmark = require(outputFile); | ||
resolve(); | ||
}); | ||
}) | ||
); | ||
|
||
it("webpack runs to completion", () => void webpackBenchmark.fn()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,29 @@ module.exports = [ | |
resolve: { | ||
alias: { | ||
fs: require.resolve("./src/vfs"), | ||
module: require.resolve("./src/mocks/dummy") | ||
"graceful-fs": require.resolve("./src/vfs"), | ||
module: require.resolve("./src/mocks/dummy"), | ||
chokidar: require.resolve("./src/mocks/chokidar"), | ||
"uglify-js": require.resolve("./src/mocks/dummy"), | ||
// These modules are used by virtualfs to fake async fs calls | ||
"core-js/library/fn/set-immediate": require.resolve( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does that work with running the benchmark suite via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See below |
||
"./src/mocks/set-immediate" | ||
), | ||
"core-js/library/fn/clear-immediate": require.resolve( | ||
"./src/mocks/clear-immediate" | ||
) | ||
} | ||
}, | ||
node: { | ||
setImmediate: false, // this disables also clearImmediate | ||
process: false | ||
}, | ||
plugins: [ | ||
new webpack.ProvidePlugin({ | ||
setImmediate: require.resolve("./src/mocks/set-immediate"), | ||
clearImmediate: require.resolve("./src/mocks/clear-immediate"), | ||
process: require.resolve("./src/mocks/process") | ||
}), | ||
new webpack.BannerPlugin({ | ||
banner: | ||
"// Required for JavaScript engine shells.\n" + | ||
|
@@ -46,10 +65,28 @@ module.exports = [ | |
alias: { | ||
define: require.resolve("./src/mocks/dummy"), | ||
fs: require.resolve("./src/vfs"), | ||
module: require.resolve("./src/mocks/dummy") | ||
"graceful-fs": require.resolve("./src/vfs"), | ||
module: require.resolve("./src/mocks/dummy"), | ||
chokidar: require.resolve("./src/mocks/chokidar"), | ||
"uglify-js": require.resolve("./src/mocks/dummy"), | ||
"core-js/library/fn/set-immediate": require.resolve( | ||
"./src/mocks/set-immediate" | ||
), | ||
"core-js/library/fn/clear-immediate": require.resolve( | ||
"./src/mocks/clear-immediate" | ||
) | ||
} | ||
}, | ||
node: { | ||
setImmediate: false, | ||
process: false | ||
}, | ||
plugins: [ | ||
new webpack.ProvidePlugin({ | ||
setImmediate: require.resolve("./src/mocks/set-immediate"), | ||
clearImmediate: require.resolve("./src/mocks/clear-immediate"), | ||
process: require.resolve("./src/mocks/process") | ||
}), | ||
new CopyWebpackPlugin([{ from: "style.css" }, { from: "Logo.png" }]), | ||
new webpack.BannerPlugin({ | ||
banner: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary because the webpack test needs to be built with webpack first. This watch ignore pattern fixes an infinite loop issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do this as a separate PR? Just adding the
jest.config.js
file. This seems useful on it's own.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to ignore that path without the webpack test because other tests are not writing any files. Personally, I wouldn't add that configuration when it's not necessary. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.