Bug Tracker

Opened 9 years ago

Closed 9 years ago

#8262 closed bug (wontfix)

try/catch inside jQuery.style() has a negative impact on perf in Safari and Opera

Reported by: lrbabe Owned by:
Priority: low Milestone: 1.next
Component: css Version: 1.5
Keywords: Cc:
Blocked by: Blocking:

Description

To prevent IE from throwing errors when 'invalid' values are provided, the line of code that sets a value to style property has been wrapped by a try/catch (see #5509)

This has a highly negative impact on performance both in Safari5 and Opera11, as shown by this test: http://jsperf.com/try-catch-impact-style#results

We could add a feature test to jQuery to detect when the browser throws an error for an invalid value and add it to jQuery.support.invalidStyle. We would then change the code in css.js to

jQuery.support.invalidStyle ?
    try { style[ name ] = value; } catch(e) {}:
    style[ name ] = value;

Change History (4)

comment:1 Changed 9 years ago by lrbabe

Oops, the try/catch is inside jQuery.style, not jQuery.fn.style

comment:2 Changed 9 years ago by jitter

Component: unfiledcss
Priority: undecidedlow
Status: newopen
Summary: try/catch inside fn.style() has a negative impact on perf in Safari and Operatry/catch inside jQuery.style() has a negative impact on perf in Safari and Opera

comment:3 Changed 9 years ago by lrbabe

On the other hand, a patched jQuery performs even worse in Firefox and Opera and only slightly better in Chrome and Safari. http://jsperf.com/jquery-style-try-catch-impact

It is probably better to leave it as is right now.

comment:4 Changed 9 years ago by jitter

Resolution: wontfix
Status: openclosed

Closing as trying to avoid the try/catch makes situation even worse.

Note: See TracTickets for help on using tickets.