Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#9885 closed task (fixed)

[patch/cla] dijit.getEnclosingWidget optimization

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

Description

Cache node.getAttribute("widgetId") in a local variable to improve loop performance.

dijit.getEnclosingWidget = function(/* DOMNode */ node) {
    while(node) {
        var widgetId = node.getAttribute && node.getAttribute("widgetId");
        if(widgetId) {
            return dijit.registry.byId(widgetId);
        }
        node = node.parentNode;
    }
    return null;
};

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

2.) Run

var getEnclosingWidget = function (/* DOMNode */ node) {
    while(node) {
        var widgetId = node.getAttribute && node.getAttribute("widgetId");
        if(widgetId) {
            return dijit.registry.byId(widgetId);
        }
        node = node.parentNode;
    }
    return null;
};

var id = "dijit_MenuItem_42";
var node = dojo.byId(id);

console.time('old');
for (var i = 0; i < 100000; i++) {
    dijit.getEnclosingWidget(node);
}
console.timeEnd('old');

console.time('new');
for (var i = 0; i < 100000; i++) {
    getEnclosingWidget(node);
}
console.timeEnd('new');


Test results:

Safari 4 (Win): 409ms --> 195ms
FF 3.5: 740ms --> 473ms
IE 6: 5312ms --> 3219ms
Chrome 4: 298ms --> 109ms
IE 8: 1687ms --> 1063ms (test on another PC)

Change History (4)

comment:1 Changed 10 years ago by bill

Milestone: tbd1.4

Sure, make sense.

comment:2 Changed 10 years ago by bill

Owner: set to bill
Status: newassigned

comment:3 Changed 10 years ago by bill

Resolution: fixed
Status: assignedclosed

(In [20107]) Dijit performance optimizations from Les Szklanny (CLA on file), thanks! Fixes #9885, #9875, #9879, refs #9131. !strict

comment:4 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.