Skip to main content

Bug Tracker

Side navigation

#3424 closed enhancement (fixed)

Opened September 29, 2008 09:14PM UTC

Closed May 04, 2009 02:30AM UTC

Last modified March 14, 2012 05:56PM UTC

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@apple.com
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').

Attachments (0)
Change History (2)

Changed October 01, 2008 02:20PM UTC by flesler comment:1

type: bugenhancement

Changed May 04, 2009 02:30AM UTC by brandon comment:2

resolution: → fixed
status: newclosed

This was addressed in 1.3