Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12885 closed feature (notabug)

Optimize jQuery.expr.filters.hidden

Reported by: dmethvin Owned by: timmywil
Priority: low Milestone: 1.9
Component: css Version: 1.8.3
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by dmethvin)

http://forum.jquery.com/topic/optimize-jquery-expr-filters-hidden

Wouldn't it make sense to alter the order of the expressions in jQuery.expr.filters.hidden to only do the expensive work (elem.offsetWidth) after evaluating the parts that don't trigger a reflow? In the case the element is determined to be hidden by the style, it does not trigger a reflow anymore, what would be a nice behavior for a hidden element.

So instead of

return ( elem.offsetWidth === 0 && elem.offsetHeight === 0 ) || (!jQuery.support.reliableHiddenOffsets && ((elem.style && elem.style.display) || curCSS( elem, "display" )) === "none");

do

return (!jQuery.support.reliableHiddenOffsets && ((elem.style && elem.style.display) || curCSS( elem, "display" )) === "none") || ( elem.offsetWidth === 0 && elem.offsetHeight === 0 );

Roel

Change History (7)

comment:1 Changed 7 years ago by dmethvin

Component: unfiledcss
Description: modified (diff)
Milestone: None1.9
Priority: undecidedlow
Status: newopen

comment:2 Changed 7 years ago by timmywil

I'm fine with it, but isn't display calculation a lot more expensive in IE than .offsetWidth/.offsetHeight?

comment:3 Changed 7 years ago by dmethvin

I think display just looks at the property for that element so no recalc should be required. The offset properties definitely require a recalc if one hasn't already been done, I'm always seeing big delays on offsetWidth/Height in profile runs for IE.

comment:4 Changed 7 years ago by r.spilker@…

comment:5 Changed 7 years ago by timmywil

@dmethvin: I'm wondering, is offsetWidth/Height faster even when the codepath hits defaultDisplay? But even if it is, this is probably a better way to go.

comment:6 Changed 7 years ago by timmywil

Owner: set to timmywil
Status: openassigned
Version: git1.8.3

Will create a perf

comment:7 Changed 7 years ago by dmethvin

Resolution: notabug
Status: assignedclosed

Based on the perf we decided not to land this.

Note: See TracTickets for help on using tickets.