Bug Tracker

Modify

Ticket #8262 (closed bug: wontfix)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 2 years ago by lrbabe

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

comment:2 Changed 2 years ago by jitter

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to css
  • Summary changed from try/catch inside fn.style() has a negative impact on perf in Safari and Opera to try/catch inside jQuery.style() has a negative impact on perf in Safari and Opera

comment:3 Changed 2 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 2 years ago by jitter

  • Status changed from open to closed
  • Resolution set to wontfix

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.