Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#3424 closed enhancement (fixed)

curCSS does expensive, unnecessary checks on every call when used in WebKit

Reported by: bdash Owned by:
Priority: major Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc: mrowe@…
Blocked by: Blocking:

Description

curCSS uses a "color" function in order to detect an old WebKit bug and work around it. This function is currently as follows:

// A helper method for determining if an element's values are broken
function color( elem ) {
	if ( !jQuery.browser.safari )
		return false;

	// defaultView is cached
	var ret = defaultView.getComputedStyle( elem, null );
	return !ret || ret.getPropertyValue("color") == "";
}

This is evaluated on every call to curCSS, and is relatively expensive. We were able to improve the performance of a simple jQuery `.offset()` performance test by 20% by improving the performance of `getPropertyValue('color')`.

Given that the WebKit bug that this is intending to work around only affects Safari 2.0 and older, and the expensive nature of this check, I would suggest that this code should be changed to explicitly version check Safari and only attempt to use the workaround in affected versions of WebKit. In addition, the browser check should be hoisted out of the function to further reduce the overhead in browsers that do not exhibit the bug. The resulting code would look something like the following:

// A helper method for determining if an element's computed style properties are broken, which
// happens in versions of WebKit prior to Safari 3 due to <https://bugs.webkit.org/show_bug.cgi?id=12384>.
function colorSafari2AndOlder ( elem ) {
	// defaultView is cached
	var ret = defaultView.getComputedStyle( elem, null );
	return !ret || ret.getPropertyValue("color") == "";
}

var color = jQuery.browser.safari && jQuery.browser.version < 500.0 ? colorSafari2AndOlder : function () { return false; };

This code gives a 25% speedup on the .offset() test linked above in Safari 3.1.2 and a 10% speedup in the latest WebKit nightly build, which contains the optimization for getPropertyValue('color').

Change History (2)

comment:1 Changed 11 years ago by flesler

Type: bugenhancement

comment:2 Changed 11 years ago by brandon

Resolution: fixed
Status: newclosed

This was addressed in 1.3

Note: See TracTickets for help on using tickets.