Opened 15 years ago

Closed 15 years ago

#2316 closed defect (wontfix)

[patch][ccla] Performance improvement for getComputedStyle

Reported by: [email protected] Owned by: anonymous
Priority: high Milestone:
Component: Style Version: 0.9
Keywords: Cc:
Blocked By: Blocking:


Every time dojo.html.getComputedStyle() is called, it calls toSelectorCase() and toCamelCase(). Since the dojo getBox, etc functions all go through here it makes a major performance hit repeating the string manipulations.

I wonder if there should be some internal shortcut functions to make some of this quicker? In the meantime, here's a patch which saves 17% :)

toCamelCase is only used for MSIE so this patch moves that conversion into the IE-only block.

Brief metrics on my machine (FF1.5/XP): Time to call getContentBox() 2000x before patch: ~6.9s Time to call getContentBox() 2000x after patch: ~5.7s (17% saving)

Index: src/html/style.js
--- src/html/style.js   (revision 7029)
+++ src/html/style.js   (working copy)
@@ -218,7 +218,6 @@
        node = dojo.byId(node);
        // cssSelector may actually be in camel case, so force selector version
        var cssSelector = dojo.html.toSelectorCase(cssSelector);
-       var property = dojo.html.toCamelCase(cssSelector);
        if(!node || !{
                return inValue;
        } else if (document.defaultView && dojo.html.isDescendantOf(node, node.ownerDocument)){ // W3, gecko, KHTML
@@ -237,6 +236,7 @@
        } else if(node.currentStyle){ // IE
+               var property = dojo.html.toCamelCase(cssSelector);
                return node.currentStyle[property];     //      integer

CLA: One Track Mind Ltd.

Change History (1)

comment:1 Changed 15 years ago by Adam Peller

Resolution: wontfix
Status: newclosed

Patch got stale and appears to have been fixed by [7379], but thanks anyways.

Note: See TracTickets for help on using tickets.