1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,414
    Vote Rating
    179
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      0  

    Default Efficient JavaScript article

    Efficient JavaScript article


    FYI

    Here's an interesting JS article:

    http://dev.opera.com/articles/view/e...nt-javascript/

    These points were new to me:

    8. Use strings accumulator-style
    9. Primitive operations can be faster than function calls

    Take a look at the Ext.draw.CompositeSprite.getBBox() method.

    It uses Math.min and Math.max in a very tight loop. I think we could apply point #9 here

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,549
    Vote Rating
    873
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I would have to agree although I wouldn't expect too big of performance bump. Every little bit counts though I guess
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,414
    Vote Rating
    179
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      0  

    Default


    Quote Originally Posted by LesJ View Post
    FYI
    Take a look at the Ext.draw.CompositeSprite.getBBox() method.

    It uses Math.min and Math.max in a very tight loop. I think we could apply point #9 here
    I just checked the nightly build. I see that the CompositeSprite.getBBox method can skip sprites from bbox calculations when the sprite has the bboxExcluded (true) attribute. This is a very simple an effective feature. I hope this is not just for internal use. I have a large number of sprites that can be excluded, so this should speed up bbox calculations.

  4. #4
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,414
    Vote Rating
    179
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    I would have to agree although I wouldn't expect too big of performance bump. Every little bit counts though I guess
    The getBBox method could be optimized further by assigning Max.min and Math.max to a local variable. This would reduce scope traversal.

    The bold vars are not used.

    I like that you can exclude sprites from BBox calculations. This was added in B3.

    var max = Math.max

    Code:
        getBBox: function() {
            var i = 0,
                sprite,
                bb,
                items = this.items,
                len = this.length,
                infinity = Infinity,
                minX = infinity,
                maxHeight = -infinity,
                minY = infinity,
                maxWidth = -infinity,
                maxWidthBBox, maxHeightBBox;
            
            for (; i < len; i++) {
                sprite = items[i];
                if (sprite.el && ! sprite.bboxExcluded) {
                    bb = sprite.getBBox();
                    minX = Math.min(minX, bb.x);
                    minY = Math.min(minY, bb.y);
                    maxHeight = Math.max(maxHeight, bb.height + bb.y);
                    maxWidth = Math.max(maxWidth, bb.width + bb.x);
                }
            }
            
            return {
                x: minX,
                y: minY,
                height: maxHeight - minY,
                width: maxWidth - minX
            };
        }

Thread Participants: 1