You found a bug! We've classified it as EXTJS-7491 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,314
    Vote Rating
    110
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default object.hasOwnProperty usage

    object.hasOwnProperty usage


    I think the way the hasOwnProperty method is used in Ext JS is not very efficient.

    See my modification below. The new code avoids long property lookups all the way to Object by caching the hasOwnProperty method in a local variable. This should improve performance.

    Code:
    Ext.define('Ext.util.Observable', {
        ...
        removeManagedListener : function(item, ename, fn, scope) {
            var me = this,
                ...,
                hasOwn = Object.prototype.hasOwnProperty; // <-- added
    
    
            if (typeof ename !== 'string') {
                options = ename;
                for (ename in options) {
                    // if (options.hasOwnProperty(ename)) {
                    if (hasOwn.call(options, ename)) {     
                        config = options[ename];
                        if (!me.eventOptionsRe.test(ename)) {
                            me.removeManagedListener(item, ename, config.fn || config, config.scope || options.scope);
                        }
                    }
                }
            }
            ...
        },
    ***Edit
    Performance improvement is minor, but it still might be worth it because it's a simple change.

    http://jsperf.com/hasownproperty-caching
    Last edited by LesJ; 8 Oct 2012 at 2:33 PM. Reason: Add test link

  2. #2
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,314
    Vote Rating
    110
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      1  

    Default


    Hmm... no comment?

    I see that Ext JS is already using the 'caching' technique in the context of the Object.prototype.toString method, but the Object.prototype.hasOwnProperty method is left out.

    Keep in mind that Ext JS has fairly long prototype chains, so it would be a good idea to save a reference to core methods such as hasOwnProperty. I checked some other JS libraries, and they use this technique.

    Of course, this won't provide a knockout performance gain, but such small improvements will add up and are worth considering.

  3. #3
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,314
    Vote Rating
    110
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default


    The ticket was closed and there's was no comment. I was at least expecting a comment about this issue. This is disappointing.

    Please note that this is not a bug that can be reproduced, but a suggestion for improvement. Other JS libraries use this technique and it's well known JS pattern for improving performance.

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,854
    Vote Rating
    610
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Basically:

    1) The wasn't a consistent performance improvement across browsers. It was better in most, but not all.
    2) The amount of improvement was a fraction of a percent, it's a micro optimization that's likely to have little or no noticeable impact.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Thread Participants: 1