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 comment:1
component: | unfiled → css |
---|---|
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 → 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 |
milestone: | None → 1.9 |
priority: | undecided → low |
status: | new → open |
Changed November 12, 2012 04:48PM UTC by 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 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 comment:4
Created pull request: https://github.com/jquery/jquery/pull/1027
Changed November 12, 2012 07:25PM UTC by 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 comment:6
owner: | → timmywil |
---|---|
status: | open → assigned |
version: | git → 1.8.3 |
Will create a perf
Changed December 12, 2012 04:14PM UTC by comment:7
resolution: | → notabug |
---|---|
status: | assigned → closed |
Based on the perf we decided not to land this.