From 4c40bcc2c55f549e055aa05b3a53059e5610190a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 27 Jan 2011 10:06:56 -0500 Subject: [PATCH] add some time instrumentation --- bin/messc | 3 +- lib/mess/renderer.js | 70 +++++++++++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/bin/messc b/bin/messc index 5b24524..234a549 100755 --- a/bin/messc +++ b/bin/messc @@ -76,6 +76,7 @@ fs.readFile(input, 'utf-8', function (e, data) { new mess.Renderer({ filename: input, + debug: options.debug, local_data_dir: path.dirname(input), }).render(data, function(err, output) { if (err) { @@ -88,7 +89,7 @@ fs.readFile(input, 'utf-8', function (e, data) { sys.puts(output); } else { var duration = (+new Date) - start; - console.log('Benchmark: ' + (duration / 1000) + 'ms'); + console.log('Benchmark: ' + (duration) + 'ms'); } } }); diff --git a/lib/mess/renderer.js b/lib/mess/renderer.js index 1bb5acc..0b3bd20 100644 --- a/lib/mess/renderer.js +++ b/lib/mess/renderer.js @@ -16,7 +16,8 @@ require.paths.unshift(path.join(__dirname, '..', 'lib')); */ mess.Renderer = function Renderer(env) { - env = _.extend(env, {}); + env = _.extend({}, env); + if (!env.debug) env.debug = false; if (!env.data_dir) env.data_dir = '/tmp/'; if (!env.local_data_dir) env.local_data_dir = ''; if (!env.validation_data) env.validation_data = false; @@ -180,19 +181,21 @@ mess.Renderer = function Renderer(env) { function compileStyles(e, results) { var options = {}, group = this.group(); - for (var i = 0, l = results.length; i < l; i++) { + results.forEach(function(result) { var next = group(); + var parsingTime = +new Date; new mess.Parser(_.extend(_.extend({ - filename: results[i][0] - }, that.env), this.env)).parse(results[i][1], + filename: result[0] + }, that.env), this.env)).parse(result[1], function(err, tree) { if (err) { mess.writeError(err, options); throw err; } else { + if (env.debug) console.warn('Parsing time: ' + ((new Date - parsingTime)) + 'ms (' + result[0] + ')'); try { next(err, [ - results[i][0], + result[0], tree]); return; } catch (e) { @@ -201,7 +204,7 @@ mess.Renderer = function Renderer(env) { } } }); - } + }); }, function waitForCompilation(err, res) { callback(err, m, res); @@ -215,6 +218,7 @@ mess.Renderer = function Renderer(env) { * symbolizer each */ splitSymbolizers: function(definitions) { + var splitTime = +new Date; var bySymbolizer = {}; for (var i = 0; i < definitions.length; i++) { definitions[i].symbolizers().forEach(function(sym) { @@ -226,6 +230,7 @@ mess.Renderer = function Renderer(env) { definitions[i].filterSymbolizer(sym)); }); } + if (env.debug) console.warn('Splitting symbolizers: ' + ((new Date - splitTime)) + 'ms'); return bySymbolizer; }, @@ -235,6 +240,7 @@ mess.Renderer = function Renderer(env) { * ancestors to them. */ processChain: function(definitions) { + var processTime = +new Date(); // definitions are ordered in specificity, // high to low // @@ -267,7 +273,9 @@ mess.Renderer = function Renderer(env) { } } - return this.resolveConditions(winners); + if (env.debug) console.warn('Processing time: ' + ((new Date - processTime)) + 'ms'); + + return winners; }, removeDuplicateSelectors: function(selectors) { @@ -301,26 +309,29 @@ mess.Renderer = function Renderer(env) { }, resolveConditions: function(definitions) { + var resolvingTime = +new Date; + var mergeTimeTotal = 0; var rules = []; var previousSelectors = []; // detect non-conflicting rulesets - var key = null, - shortcut = true, - filters; - for (var i = 0; i < definitions.length; i++) { - filters = definitions[i].selector.filters; - if (!(filters.length && - shortcut && (((key == null) && (key = filters[0].key)) || - (key == filters[0].key)) && - (filters.length == 1) && - (filters[0].op.value == '='))) { - shortcut = false; - break; - } - } + // var key = null, + // shortcut = true, + // filters; + // for (var i = 0; i < definitions.length; i++) { + // filters = definitions[i].selector.filters; + // if (!(filters.length && + // shortcut && (((key == null) && (key = filters[0].key)) || + // (key == filters[0].key)) && + // (filters.length == 1) && + // (filters[0].op.value == '='))) { + // shortcut = false; + // break; + // } + // } + // + // if (shortcut) return definitions; - if (shortcut) return definitions; for (var i = 0; i < definitions.length; i++) { if (!definitions[i].selector.sound()) { @@ -331,6 +342,7 @@ mess.Renderer = function Renderer(env) { var selectors = [ definitions[i].selector.clone() ]; // Add the negated previous selectors. + for (var j = 0; j < previousSelectors.length; j++) { for (var k = selectors.length - 1; k >= 0; k--) { var splitSelectors = selectors[k].mergeOrConditions(previousSelectors[j]); @@ -346,6 +358,7 @@ mess.Renderer = function Renderer(env) { } } } + previousSelectors.push(definitions[i].selector.negate()); selectors = this.removeDuplicateSelectors(selectors); @@ -358,6 +371,8 @@ mess.Renderer = function Renderer(env) { } } + if (env.debug) console.warn('Resolving time: ' + ((new Date - resolvingTime)) + 'ms'); + return rules; }, @@ -432,10 +447,14 @@ mess.Renderer = function Renderer(env) { for (var sym in bySymbolizer) { // Create styles out of chains of one-symbolizer rules, // and assign those styles to layers + + var definitions = that.processChain(bySymbolizer[sym]); + definitions = that.resolveConditions(definitions); + var new_style = new mess.tree.Style( l.id, sym, - that.processChain(bySymbolizer[sym])); + definitions); l.styles.push(new_style.name()); // env.effects can be modified by this call output.push(new_style.toXML(env)); @@ -492,11 +511,16 @@ mess.Renderer = function Renderer(env) { render: function(str, callback) { var m = JSON.parse(str), that = this; + + var localizingTime = +new Date; this.localizeExternals(m, function(err, res) { that.ensureSRS(res, function(err, res) { that.localizeStyle(res, function(err, res) { + if (env.debug) console.warn('Localizing time: ' + ((new Date - localizingTime)) + 'ms'); that.style(res, function(err, m, res) { + var compilingTime = +new Date; that.template(err, m, res, function(err, res) { + if (env.debug) console.warn('COMPILING TIME: ' + ((new Date - compilingTime)) + 'ms'); callback(err, res); }); });