Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#9900 closed task (fixed)

[patch/cla] dijit.WidgetSet.byClass() optimization

Reported by: Les Owned by: bill
Priority: high Milestone: 1.4
Component: Dijit Version: 1.3.2
Keywords: dijit.WidgetSet Cc:
Blocked By: Blocking:

Description

This is another simple code change that improved byClass() speed.

byClass: function(/*String*/ cls){
	var res = new dijit.WidgetSet(), id, widget;
	for(id in this._hash){
		widget = this._hash[id];
		if(widget.declaredClass == cls) {
			res.add(widget);
		}
	}
	return res; // dijit.WidgetSet
}

Test setup:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/test_Menu.html# Run:

var byClass = function(/*String*/ cls){
	var res = new dijit.WidgetSet(), id, widget;
	for(id in dijit.registry._hash){
		widget = dijit.registry._hash[id];
		if(widget.declaredClass == cls) {
			res.add(widget);
		}
	}
	return res; // dijit.WidgetSet
}

console.time('old');
for(var i=0; i<1000; i++) {
   dijit.registry.byClass('dijit.MenuItem');
}
console.timeEnd('old');

console.time('new');
for(var i=0; i<1000; i++) {
   byClass('dijit.MenuItem');
}
console.timeEnd('new');

dijit.registry.byClass('dijit.MenuItem').length == byClass('dijit.MenuItem').length;

Results:

FF 3.5: 466ms --> 245ms
Chrome 4: 134ms --> 114ms
IE 6: 2716ms --> 2232ms
IE 8: 766ms --> 656ms
Safari 4 (Win): 202ms --> 108ms

Change History (3)

comment:1 Changed 10 years ago by bill

Milestone: tbd1.4
Owner: set to bill
Status: newassigned

OK, although it's increasing the code size. BTW console.time() and console.timeEnd() do not work on IE, or at least not on IE8; not with the IE8 developer console open anyway.

comment:2 Changed 10 years ago by bill

Resolution: fixed
Status: assignedclosed

(In [20121]) Dijit performance optimizations, albeit at the cost of some code size increase, from Les Szklanny (CLA on file), thanks! Fixes #9899, #9900. !strict

comment:3 Changed 10 years ago by bill

Type: enhancementtask

seems like these aren't really enhancements from the users' point of view, labeling as tasks instead

Note: See TracTickets for help on using tickets.