report timing breakdown (#2000)
fix corner cases with `sourceMap` fixes #1998
This commit is contained in:
@@ -126,7 +126,7 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
the source map.
|
the source map.
|
||||||
`url` If specified, path to the source map to append in
|
`url` If specified, path to the source map to append in
|
||||||
`//# sourceMappingURL`.
|
`//# sourceMappingURL`.
|
||||||
--stats Display operations run time on STDERR.
|
--timings Display operations run time on STDERR.
|
||||||
--toplevel Compress and/or mangle variables in top level scope.
|
--toplevel Compress and/or mangle variables in top level scope.
|
||||||
--verbose Print diagnostic messages.
|
--verbose Print diagnostic messages.
|
||||||
--warn Print warning messages.
|
--warn Print warning messages.
|
||||||
|
|||||||
14
bin/uglifyjs
14
bin/uglifyjs
@@ -39,7 +39,7 @@ program.option("--keep-fnames", "Do not mangle/drop function names. Useful for c
|
|||||||
program.option("--name-cache <file>", "File to hold mangled name mappings.");
|
program.option("--name-cache <file>", "File to hold mangled name mappings.");
|
||||||
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
||||||
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_source_map());
|
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_source_map());
|
||||||
program.option("--stats", "Display operations run time on STDERR.")
|
program.option("--timings", "Display operations run time on STDERR.")
|
||||||
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
|
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
|
||||||
program.option("--verbose", "Print diagnostic messages.");
|
program.option("--verbose", "Print diagnostic messages.");
|
||||||
program.option("--warn", "Print warning messages.");
|
program.option("--warn", "Print warning messages.");
|
||||||
@@ -115,10 +115,10 @@ if (program.output == "ast") {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (program.parse) {
|
if (program.parse) {
|
||||||
if (program.parse.acorn || program.parse.spidermonkey) {
|
if (!program.parse.acorn && !program.parse.spidermonkey) {
|
||||||
if (program.sourceMap) fatal("ERROR: inline source map only works with built-in parser");
|
|
||||||
} else {
|
|
||||||
options.parse = program.parse;
|
options.parse = program.parse;
|
||||||
|
} else if (program.sourceMap && program.sourceMap.content == "inline") {
|
||||||
|
fatal("ERROR: inline source map only works with built-in parser");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var convert_path = function(name) {
|
var convert_path = function(name) {
|
||||||
@@ -172,7 +172,7 @@ function run() {
|
|||||||
UglifyJS.AST_Node.warn_function = function(msg) {
|
UglifyJS.AST_Node.warn_function = function(msg) {
|
||||||
console.error("WARN:", msg);
|
console.error("WARN:", msg);
|
||||||
};
|
};
|
||||||
if (program.stats) program.stats = Date.now();
|
if (program.timings) options.timings = true;
|
||||||
try {
|
try {
|
||||||
if (program.parse) {
|
if (program.parse) {
|
||||||
if (program.parse.acorn) {
|
if (program.parse.acorn) {
|
||||||
@@ -259,7 +259,9 @@ function run() {
|
|||||||
return value instanceof UglifyJS.Dictionary ? value.toObject() : value;
|
return value instanceof UglifyJS.Dictionary ? value.toObject() : value;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
if (program.stats) console.error("Elapsed:", Date.now() - program.stats);
|
if (result.timings) for (var phase in result.timings) {
|
||||||
|
console.error("- " + phase + ": " + result.timings[phase].toFixed(3) + "s");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fatal(message) {
|
function fatal(message) {
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ function set_shorthand(name, options, keys) {
|
|||||||
function minify(files, options) {
|
function minify(files, options) {
|
||||||
var warn_function = AST_Node.warn_function;
|
var warn_function = AST_Node.warn_function;
|
||||||
try {
|
try {
|
||||||
if (typeof files == "string") {
|
|
||||||
files = [ files ];
|
|
||||||
}
|
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
compress: {},
|
compress: {},
|
||||||
ie8: false,
|
ie8: false,
|
||||||
@@ -41,10 +38,14 @@ function minify(files, options) {
|
|||||||
output: {},
|
output: {},
|
||||||
parse: {},
|
parse: {},
|
||||||
sourceMap: false,
|
sourceMap: false,
|
||||||
|
timings: false,
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
warnings: false,
|
warnings: false,
|
||||||
wrap: false,
|
wrap: false,
|
||||||
}, true);
|
}, true);
|
||||||
|
var timings = options.timings && {
|
||||||
|
start: Date.now()
|
||||||
|
};
|
||||||
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
||||||
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
||||||
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
||||||
@@ -75,10 +76,14 @@ function minify(files, options) {
|
|||||||
warnings.push(warning);
|
warnings.push(warning);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (timings) timings.parse = Date.now();
|
||||||
var toplevel;
|
var toplevel;
|
||||||
if (files instanceof AST_Toplevel) {
|
if (files instanceof AST_Toplevel) {
|
||||||
toplevel = files;
|
toplevel = files;
|
||||||
} else {
|
} else {
|
||||||
|
if (typeof files == "string") {
|
||||||
|
files = [ files ];
|
||||||
|
}
|
||||||
options.parse = options.parse || {};
|
options.parse = options.parse || {};
|
||||||
options.parse.toplevel = null;
|
options.parse.toplevel = null;
|
||||||
for (var name in files) {
|
for (var name in files) {
|
||||||
@@ -95,19 +100,23 @@ function minify(files, options) {
|
|||||||
if (options.wrap) {
|
if (options.wrap) {
|
||||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
toplevel = toplevel.wrap_commonjs(options.wrap);
|
||||||
}
|
}
|
||||||
if (options.compress) {
|
if (timings) timings.scope1 = Date.now();
|
||||||
toplevel.figure_out_scope(options.mangle);
|
if (options.compress) toplevel.figure_out_scope(options.mangle);
|
||||||
toplevel = new Compressor(options.compress).compress(toplevel);
|
if (timings) timings.compress = Date.now();
|
||||||
}
|
if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
|
||||||
|
if (timings) timings.scope2 = Date.now();
|
||||||
|
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
||||||
|
if (timings) timings.mangle = Date.now();
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
toplevel.figure_out_scope(options.mangle);
|
|
||||||
base54.reset();
|
base54.reset();
|
||||||
toplevel.compute_char_frequency(options.mangle);
|
toplevel.compute_char_frequency(options.mangle);
|
||||||
toplevel.mangle_names(options.mangle);
|
toplevel.mangle_names(options.mangle);
|
||||||
if (options.mangle.properties) {
|
|
||||||
toplevel = mangle_properties(toplevel, options.mangle.properties);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (timings) timings.properties = Date.now();
|
||||||
|
if (options.mangle && options.mangle.properties) {
|
||||||
|
toplevel = mangle_properties(toplevel, options.mangle.properties);
|
||||||
|
}
|
||||||
|
if (timings) timings.output = Date.now();
|
||||||
var result = {};
|
var result = {};
|
||||||
if (options.output.ast) {
|
if (options.output.ast) {
|
||||||
result.ast = toplevel;
|
result.ast = toplevel;
|
||||||
@@ -123,7 +132,9 @@ function minify(files, options) {
|
|||||||
root: options.sourceMap.root
|
root: options.sourceMap.root
|
||||||
});
|
});
|
||||||
if (options.sourceMap.includeSources) {
|
if (options.sourceMap.includeSources) {
|
||||||
for (var name in files) {
|
if (files instanceof AST_Toplevel) {
|
||||||
|
throw new Error("original source content unavailable");
|
||||||
|
} else for (var name in files) {
|
||||||
options.output.source_map.get().setSourceContent(name, files[name]);
|
options.output.source_map.get().setSourceContent(name, files[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,6 +153,18 @@ function minify(files, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (timings) {
|
||||||
|
timings.end = Date.now();
|
||||||
|
result.timings = {
|
||||||
|
parse: 1e-3 * (timings.scope1 - timings.parse),
|
||||||
|
scope: 1e-3 * (timings.compress - timings.scope1 + timings.mangle - timings.scope2),
|
||||||
|
compress: 1e-3 * (timings.scope2 - timings.compress),
|
||||||
|
mangle: 1e-3 * (timings.properties - timings.mangle),
|
||||||
|
properties: 1e-3 * (timings.output - timings.properties),
|
||||||
|
output: 1e-3 * (timings.end - timings.output),
|
||||||
|
total: 1e-3 * (timings.end - timings.start)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
result.warnings = warnings;
|
result.warnings = warnings;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ var args = process.argv.slice(2);
|
|||||||
if (!args.length) {
|
if (!args.length) {
|
||||||
args.push("-mc");
|
args.push("-mc");
|
||||||
}
|
}
|
||||||
args.push("--stats");
|
args.push("--timings");
|
||||||
var urls = [
|
var urls = [
|
||||||
"https://code.jquery.com/jquery-3.2.1.js",
|
"https://code.jquery.com/jquery-3.2.1.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js",
|
||||||
@@ -29,12 +29,7 @@ function done() {
|
|||||||
var info = results[url];
|
var info = results[url];
|
||||||
console.log();
|
console.log();
|
||||||
console.log(url);
|
console.log(url);
|
||||||
var elapsed = 0;
|
console.log(info.log);
|
||||||
console.log(info.log.replace(/Elapsed: ([0-9]+)\s*/g, function(match, time) {
|
|
||||||
elapsed += 1e-3 * parseInt(time);
|
|
||||||
return "";
|
|
||||||
}));
|
|
||||||
console.log("Run-time:", elapsed.toFixed(3), "s");
|
|
||||||
console.log("Original:", info.input, "bytes");
|
console.log("Original:", info.input, "bytes");
|
||||||
console.log("Uglified:", info.output, "bytes");
|
console.log("Uglified:", info.output, "bytes");
|
||||||
console.log("SHA1 sum:", info.sha1);
|
console.log("SHA1 sum:", info.sha1);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if (typeof phantom == "undefined") {
|
|||||||
if (!args.length) {
|
if (!args.length) {
|
||||||
args.push("-mc");
|
args.push("-mc");
|
||||||
}
|
}
|
||||||
args.push("--stats");
|
args.push("--timings");
|
||||||
var child_process = require("child_process");
|
var child_process = require("child_process");
|
||||||
try {
|
try {
|
||||||
require("phantomjs-prebuilt");
|
require("phantomjs-prebuilt");
|
||||||
|
|||||||
Reference in New Issue
Block a user