Skip to main content

Bug Tracker

Side navigation

#12885 closed feature (notabug)

Opened November 12, 2012 03:31PM UTC

Closed December 12, 2012 04:14PM UTC

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

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

Attachments (0)
Change History (7)

Changed November 12, 2012 03:33PM UTC by dmethvin comment:1

component: unfiledcss
description: 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 ); \ Roelhttp://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
milestone: None1.9
priority: undecidedlow
status: newopen

Changed November 12, 2012 04:48PM UTC by timmywil comment:2

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

Changed November 12, 2012 05:01PM UTC by dmethvin comment:3

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.

Changed November 12, 2012 06:36PM UTC by r.spilker@gmail.com comment:4

Changed November 12, 2012 07:25PM UTC by timmywil comment:5

@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.

Changed November 26, 2012 05:33PM UTC by timmywil comment:6

owner: → timmywil
status: openassigned
version: git1.8.3

Will create a perf

Changed December 12, 2012 04:14PM UTC by dmethvin comment:7

resolution: → notabug
status: assignedclosed

Based on the perf we decided not to land this.