#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 11 years ago by
Milestone: | tbd → 1.4 |
---|---|
Owner: | set to bill |
Status: | new → assigned |
comment:2 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:3 Changed 11 years ago by
Type: | enhancement → task |
---|
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.
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.