r112032 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112031‎ | r112032 | r112033 >
Date:18:49, 21 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Reduce debug print overhead, roughly a 10% speed-up on parserTests.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -443,8 +443,8 @@
444444 AsyncTokenTransformManager.prototype.onChunk = function ( tokens ) {
445445 // Set top-level callback to next transform phase
446446 var res = this.transformTokens ( tokens, this.tokenCB );
447 - this.env.dp('AsyncTokenTransformManager onChunk res.async=' + res.async +
448 - ' tokens=' + JSON.stringify( tokens ) );
 447+ this.env.dp( 'AsyncTokenTransformManager onChunk res.async=',
 448+ res.async, ' tokens=', tokens );
449449
450450 if ( ! this.tailAccumulator ) {
451451 this.emit( 'chunk', res.tokens );
@@ -574,8 +574,8 @@
575575 // tokens.pop();
576576 //}
577577
578 - this.env.dp('AsyncTokenTransformManager._returnTokens, emitting chunk: ' +
579 - JSON.stringify( tokens ) );
 578+ this.env.dp( 'AsyncTokenTransformManager._returnTokens, emitting chunk: ',
 579+ tokens );
580580
581581 this.emit( 'chunk', tokens );
582582
@@ -607,7 +607,7 @@
608608 } else {
609609 // nothing was asynchronous, so we'll have to emit end here.
610610 this.env.dp( 'AsyncTokenTransformManager.onEndEvent: synchronous done',
611 - this.loopAndDepthCheck );
 611+ this.loopAndDepthCheck );
612612 this.emit('end');
613613 this._reset();
614614 }
@@ -658,8 +658,7 @@
659659 * @param {Array} Token chunk.
660660 */
661661 SyncTokenTransformManager.prototype.onChunk = function ( tokens ) {
662 - this.env.dp('SyncTokenTransformManager.onChunk, input: ' +
663 - JSON.stringify( tokens, null, 2 ) );
 662+ this.env.dp( 'SyncTokenTransformManager.onChunk, input: ', tokens );
664663 var res,
665664 localAccum = [],
666665 localAccumLength = 0,
@@ -717,8 +716,7 @@
718717 }
719718 }
720719 }
721 - this.env.dp( 'SyncTokenTransformManager.onChunk: emitting ' +
722 - JSON.stringify( localAccum, null, 2 ) );
 720+ this.env.dp( 'SyncTokenTransformManager.onChunk: emitting ', localAccum );
723721 this.emit( 'chunk', localAccum );
724722 };
725723
@@ -941,10 +939,8 @@
942940 //console.warn( 'TokenAccumulator._returnTokens' );
943941 if ( reference === 'child' ) {
944942 tokens = tokens.concat( this.accum );
945 - this.manager.env.dp('TokenAccumulator._returnTokens child: ' +
946 - JSON.stringify( tokens, null, 2 ) +
947 - ' outstanding: ' + this.outstanding
948 - );
 943+ this.manager.env.dp( 'TokenAccumulator._returnTokens child: ',
 944+ tokens, ' outstanding: ', this.outstanding );
949945 this.accum = [];
950946 this.parentCB( tokens, this.outstanding );
951947 return null;
@@ -954,15 +950,15 @@
955951 tokens = this.accum.concat( tokens );
956952 // A sibling will transform tokens, so we don't have to do this
957953 // again.
958 - this.manager.env.dp( 'TokenAccumulator._returnTokens: ' +
959 - 'sibling done and parentCB ' +
960 - JSON.stringify( tokens ) );
 954+ this.manager.env.dp( 'TokenAccumulator._returnTokens: ',
 955+ 'sibling done and parentCB ',
 956+ tokens );
961957 this.parentCB( tokens, false );
962958 return null;
963959 } else if ( this.outstanding === 1 && notYetDone ) {
964 - this.manager.env.dp( 'TokenAccumulator._returnTokens: ' +
965 - 'sibling done and parentCB but notYetDone ' +
966 - JSON.stringify( tokens ) );
 960+ this.manager.env.dp( 'TokenAccumulator._returnTokens: ',
 961+ 'sibling done and parentCB but notYetDone ',
 962+ tokens );
967963 // Sibling is not yet done, but child is. Return own parentCB to
968964 // allow the sibling to go direct, and call back parent with
969965 // tokens. The internal accumulator is empty at this stage, as its
@@ -970,11 +966,9 @@
971967 return this.parentCB( tokens, true);
972968 } else {
973969 this.accum = this.accum.concat( tokens );
974 - this.manager.env.dp( 'TokenAccumulator._returnTokens: sibling done, but not overall. notYetDone=' +
975 - notYetDone + ', this.outstanding=' + this.outstanding +
976 - ', this.accum=' +
977 - JSON.stringify( this.accum, null, 2 ) +
978 - ' manager.title=', this.manager.title );
 970+ this.manager.env.dp( 'TokenAccumulator._returnTokens: sibling done, but not overall. notYetDone=',
 971+ notYetDone, ', this.outstanding=', this.outstanding,
 972+ ', this.accum=', this.accum, ' manager.title=', this.manager.title );
979973 }
980974
981975
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -489,7 +489,7 @@
490490 return [new TagTk( 'h' + level )]
491491 .concat(c, [new EndTagTk( 'h' + level ), spc]);
492492 }
493 - / & { dp('nomatch exit h'); clearFlag('h'); return false } { return null }
 493+ / & { /* dp('nomatch exit h'); */ clearFlag('h'); return false } { return null }
494494 ) { return r }
495495
496496 comment
@@ -1239,7 +1239,7 @@
12401240 = tas:table_start space* c:table_caption? b:table_body? te:table_end {
12411241 var res = new TagTk( 'table' );
12421242 var body = b !== '' ? b : [];
1243 - dp("body: " + pp(body));
 1243+ //dp("body: " + pp(body));
12441244 if (tas.length > 0) {
12451245 // FIXME: actually parse and build structure
12461246 //res.attribs = [new KV('data-unparsed', tas.join(''))];
@@ -1263,7 +1263,7 @@
12641264 & { setFlag('table'); return true; }
12651265 ta:generic_attribute*
12661266 {
1267 - dp("table_start " + pp(ta) + ", pos:" + pos);
 1267+ //dp("table_start " + pp(ta) + ", pos:" + pos);
12681268 return ta;
12691269 }
12701270 / & { clearFlag('table'); return false; } { return null; }
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
@@ -54,13 +54,13 @@
5555 if( atm.process( token.attribs ) ) {
5656 // Attributes were transformed synchronously
5757 this.manager.env.dp (
58 - 'sync attribs for ' + JSON.stringify( token )
 58+ 'sync attribs for ', token
5959 );
6060 // All attributes are fully expanded synchronously (no IO was needed)
6161 return { token: token };
6262 } else {
6363 // Async attribute expansion is going on
64 - this.manager.env.dp( 'async return for ' + JSON.stringify( token ));
 64+ this.manager.env.dp( 'async return for ', token );
6565 expandData.async = true;
6666 return { async: true };
6767 }
@@ -76,8 +76,7 @@
7777 AttributeExpander.prototype._returnAttributes = function ( expandData,
7878 attributes )
7979 {
80 - this.manager.env.dp( 'AttributeExpander._returnAttributes: ' +
81 - JSON.stringify(attributes) );
 80+ this.manager.env.dp( 'AttributeExpander._returnAttributes: ',attributes );
8281 // Remove the target from the attributes
8382 expandData.token.attribs = attributes;
8483 if ( expandData.async ) {
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -78,8 +78,8 @@
7979 attributes = attributes.concat( this._nameArgs( token.attribs ) );
8080 }
8181
82 - this.manager.env.dp( 'before AttributeTransformManager: ' +
83 - JSON.stringify( attributes, null, 2 ) );
 82+ this.manager.env.dp( 'before AttributeTransformManager: ',
 83+ attributes );
8484 new AttributeTransformManager(
8585 this.manager,
8686 this._returnAttributes.bind( this, tplExpandData )
@@ -88,15 +88,14 @@
8989 // Unblock finish
9090 if ( ! tplExpandData.attribsAsync ) {
9191 // Attributes were transformed synchronously
92 - this.manager.env.dp (
93 - 'sync attribs for ' + JSON.stringify( tplExpandData.target ),
 92+ this.manager.env.dp ( 'sync attribs for ', tplExpandData.target,
9493 tplExpandData.expandedArgs
9594 );
9695 // All attributes are fully expanded synchronously (no IO was needed)
9796 return this._expandTemplate ( tplExpandData );
9897 } else {
9998 // Async attribute expansion is going on
100 - this.manager.env.dp( 'async return for ' + JSON.stringify( token ));
 99+ this.manager.env.dp( 'async return for ', token );
101100 tplExpandData.overallAsync = true;
102101 return { async: true };
103102 }
@@ -117,7 +116,7 @@
118117 out.push( attribs[i] );
119118 }
120119 }
121 - this.manager.env.dp( '_nameArgs: ' + JSON.stringify( out ) );
 120+ this.manager.env.dp( '_nameArgs: ', out );
122121 return out;
123122 };
124123
@@ -127,7 +126,7 @@
128127 TemplateHandler.prototype._returnAttributes = function ( tplExpandData,
129128 attributes )
130129 {
131 - this.manager.env.dp( 'TemplateHandler._returnAttributes: ' + JSON.stringify(attributes) );
 130+ this.manager.env.dp( 'TemplateHandler._returnAttributes: ', attributes );
132131 // Remove the target from the attributes
133132 tplExpandData.attribsAsync = false;
134133 tplExpandData.target = attributes[0].v;
@@ -149,8 +148,7 @@
150149
151150
152151 if ( ! tplExpandData.target ) {
153 - this.manager.env.dp( 'No target! ' +
154 - JSON.stringify( tplExpandData, null, 2 ) );
 152+ this.manager.env.dp( 'No target! ', tplExpandData );
155153 console.trace();
156154 }
157155
@@ -179,12 +177,12 @@
180178
181179 // XXX: support async parser functions!
182180 if ( tplExpandData.overallAsync ) {
183 - this.manager.env.dp( 'TemplateHandler._expandTemplate: calling back ' +
184 - 'after parser func ' + prefix + ' with res:' + JSON.stringify( res ) );
 181+ this.manager.env.dp( 'TemplateHandler._expandTemplate: calling back ',
 182+ 'after parser func ', prefix, ' with res:', res );
185183 return tplExpandData.cb( res, false );
186184 } else {
187 - this.manager.env.dp( 'TemplateHandler._expandTemplate: sync return ' +
188 - 'after parser func ' + prefix + ' with res:' + JSON.stringify( res ) );
 185+ this.manager.env.dp( 'TemplateHandler._expandTemplate: sync return ',
 186+ 'after parser func ', prefix, ' with res:', res );
189187 return { tokens: res };
190188 //data.reset();
191189 }
@@ -249,13 +247,13 @@
250248 if ( tplExpandData.overallAsync ||
251249 ! tplExpandData.expandDone ) {
252250 tplExpandData.overallAsync = true;
253 - this.manager.env.dp( 'Async return from _expandTemplate for ' +
254 - JSON.stringify ( tplExpandData.target ) );
 251+ this.manager.env.dp( 'Async return from _expandTemplate for ',
 252+ tplExpandData.target );
255253 return { async: true };
256254 } else {
257 - this.manager.env.dp( 'Sync return from _expandTemplate for ' +
258 - JSON.stringify( tplExpandData.target ) + ' : ' +
259 - JSON.stringify( tplExpandData.result )
 255+ this.manager.env.dp( 'Sync return from _expandTemplate for ',
 256+ tplExpandData.target, ' : ',
 257+ tplExpandData.result
260258 );
261259 return tplExpandData.result;
262260 }
@@ -267,7 +265,7 @@
268266 */
269267 TemplateHandler.prototype._onChunk = function( tplExpandData, chunk ) {
270268 // We encapsulate the output by default, so collect tokens here.
271 - this.manager.env.dp( 'TemplateHandler._onChunk' + JSON.stringify( chunk ) );
 269+ this.manager.env.dp( 'TemplateHandler._onChunk', chunk );
272270 tplExpandData.resultTokens = tplExpandData.resultTokens.concat( chunk );
273271 };
274272
@@ -276,7 +274,7 @@
277275 * the template source.
278276 */
279277 TemplateHandler.prototype._onEnd = function( tplExpandData, token ) {
280 - this.manager.env.dp( 'TemplateHandler._onEnd' + JSON.stringify( tplExpandData.resultTokens ) );
 278+ this.manager.env.dp( 'TemplateHandler._onEnd', tplExpandData.resultTokens );
281279 tplExpandData.expandDone = true;
282280 var res = tplExpandData.resultTokens;
283281 // Strip 'end' tokens and trailing newlines
@@ -296,8 +294,7 @@
297295 //console.warn( 'TemplateHandler._onEnd: ' + JSON.stringify( res, null, 2 ) );
298296
299297 if ( tplExpandData.overallAsync ) {
300 - this.manager.env.dp( 'TemplateHandler._onEnd: calling back with res:' +
301 - JSON.stringify( res ) );
 298+ this.manager.env.dp( 'TemplateHandler._onEnd: calling back with res:', res );
302299 tplExpandData.cb( res, false );
303300 } else {
304301 this.manager.env.dp( 'TemplateHandler._onEnd: synchronous return!' );
@@ -313,7 +310,7 @@
314311 */
315312 TemplateHandler.prototype._processTemplateAndTitle = function( pipeline, src, title ) {
316313 // Feed the pipeline. XXX: Support different formats.
317 - this.manager.env.dp( 'TemplateHandler._processTemplateAndTitle: ' + src );
 314+ this.manager.env.dp( 'TemplateHandler._processTemplateAndTitle: ', src );
318315 pipeline.process ( src );
319316 };
320317
@@ -340,10 +337,10 @@
341338 // We are about to start an async request for a template, so mark this
342339 // template expansion as such.
343340 tplExpandData.overallAsync = true;
344 - this.manager.env.dp( 'Note: trying to fetch ' + title );
 341+ this.manager.env.dp( 'Note: trying to fetch ', title );
345342
346343 // Start a new request if none is outstanding
347 - this.manager.env.dp( 'requestQueue: ', this.manager.env.requestQueue);
 344+ this.manager.env.dp( 'requestQueue: ', this.manager.env.requestQueue );
348345 if ( this.manager.env.requestQueue[title] === undefined ) {
349346 this.manager.env.tp( 'Note: Starting new request for ' + title );
350347 this.manager.env.requestQueue[title] = new TemplateRequest( this.manager, title );
@@ -393,8 +390,8 @@
394391 res = this.manager.args[argName];
395392 } else {
396393 var defaultValue = (attributes[1] && ! attributes[1].k.length && attributes[1].v) || false;
397 - this.manager.env.dp( 'templateArg not found: ' + argName +
398 - ' vs. ' + JSON.stringify( defaultValue ) );
 394+ this.manager.env.dp( 'templateArg not found: ', argName,
 395+ ' vs. ', defaultValue );
399396 if ( defaultValue ) {
400397 res = defaultValue;
401398 } else {
@@ -474,7 +471,7 @@
475472 // XXX: handle other status codes
476473
477474 // Remove self from request queue
478 - manager.env.dp( 'trying to remove ' + title + ' from requestQueue' );
 475+ manager.env.dp( 'trying to remove ', title, ' from requestQueue' );
479476 delete manager.env.requestQueue[title];
480477 manager.env.dp( 'after deletion:', manager.env.requestQueue );
481478 });

Status & tagging log