jenkins-bot has submitted this change and it was merged. Change subject: Trace time spent in treebuilder + token transformations ......................................................................
Trace time spent in treebuilder + token transformations * This still doesn't account for time spent in the PEG tokenizer, time spent in the token transformation manager code, I/O wait time. * Dumps recorded time profile at the end. * Using Date to compute times. Good enough for a first cut since this is only used during development. Change-Id: Idd1b1932ca37c3647a47d67d6e86bf3559636034 --- M lib/config/MWParserEnvironment.js M lib/wt2html/DOMPostProcessor.js M lib/wt2html/HTML5TreeBuilder.js M lib/wt2html/TokenTransformManager.js M lib/wt2html/parser.js 5 files changed, 44 insertions(+), 1 deletion(-) Approvals: Arlolra: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/config/MWParserEnvironment.js b/lib/config/MWParserEnvironment.js index a40b68c..bfda9de 100644 --- a/lib/config/MWParserEnvironment.js +++ b/lib/config/MWParserEnvironment.js @@ -80,6 +80,9 @@ return new Page(); })(); + // Record time spent in various passes + this.timeProfile = {}; + // A passed-in cookie, if any this.cookie = options.cookie || null; @@ -152,6 +155,24 @@ } PayloadTooLargeError.prototype = Error.prototype; +MWParserEnvironment.prototype.bumpTimeUse = function(resource, time) { + if (!this.timeProfile[resource]) { + this.timeProfile[resource] = 0; + } + this.timeProfile[resource] += time; +}; + +MWParserEnvironment.prototype.printTimeProfile = function() { + console.warn("-".repeat(55)); + console.warn("Recorded times (in ms) for sync token transformations"); + console.warn("-".repeat(55)); + for (var k in this.timeProfile) { + var str = k + ' '.repeat(k.length < 30 ? 30 - k.length : 0); + console.warn(str + ": " + this.timeProfile[k]); + } + console.warn("-".repeat(55)); +}; + MWParserEnvironment.prototype.bumpParserResourceUse = function(resource, count) { var n = this.limits.wt2html[resource]; n -= (count || 1); diff --git a/lib/wt2html/DOMPostProcessor.js b/lib/wt2html/DOMPostProcessor.js index 7a0e854..fecdeae 100644 --- a/lib/wt2html/DOMPostProcessor.js +++ b/lib/wt2html/DOMPostProcessor.js @@ -431,6 +431,9 @@ // For the top-level document, we generate <head> and add it. if (this.atTopLevel) { this.addMetaData(document); + if (psd.traceFlags && psd.traceFlags.indexOf('time') !== -1) { + env.printTimeProfile(); + } } this.emit('document', document); diff --git a/lib/wt2html/HTML5TreeBuilder.js b/lib/wt2html/HTML5TreeBuilder.js index 81d3a1c..0564f49 100644 --- a/lib/wt2html/HTML5TreeBuilder.js +++ b/lib/wt2html/HTML5TreeBuilder.js @@ -102,10 +102,12 @@ }; TreeBuilder.prototype.onChunk = function(tokens) { + var s = new Date(); var n = tokens.length; for (var i = 0; i < n; i++) { this.processToken(tokens[i]); } + this.env.bumpTimeUse("HTML5 TreeBuilder", (new Date()) - s); }; TreeBuilder.prototype.onEnd = function() { diff --git a/lib/wt2html/TokenTransformManager.js b/lib/wt2html/TokenTransformManager.js index c43e14e..3671885 100644 --- a/lib/wt2html/TokenTransformManager.js +++ b/lib/wt2html/TokenTransformManager.js @@ -113,6 +113,18 @@ return a.rank - b.rank; }; +// Use a new method to create this to prevent the closure +// from holding onto more state than necessary. +TokenTransformManager.prototype.timeTracer = function(transform, traceName) { + var env = this.env; + return function() { + var s = new Date(); + var ret = transform.apply(null, arguments); + env.bumpTimeUse(traceName, (new Date()) - s); + return ret; + }; +}; + /** * Add a transform registration. * @@ -137,6 +149,10 @@ * tag name for tags, omitted for non-tags */ TokenTransformManager.prototype.addTransform = function(transformation, debugName, rank, type, name) { + var traceFlags = this.env.conf.parsoid.traceFlags; + if (traceFlags && (traceFlags.indexOf("time") !== -1)) { + transformation = this.timeTracer(transformation, debugName); + } var t = { rank: rank, name: debugName, diff --git a/lib/wt2html/parser.js b/lib/wt2html/parser.js index e1a90ba..3dffca9 100644 --- a/lib/wt2html/parser.js +++ b/lib/wt2html/parser.js @@ -482,7 +482,8 @@ // maintained across all pipelines used by the document. // (Ex: Cite state) this.resetState({toplevel: true}); - return this.first.process(input); + this.env.log('trace/time', 'Starting parse at ', new Date()); + this.first.process(input); } catch (err) { this.env.log("fatal", err); } -- To view, visit https://gerrit.wikimedia.org/r/301845 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Idd1b1932ca37c3647a47d67d6e86bf3559636034 Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits