Skip to main content

Bug Tracker

Side navigation

#1871 closed bug (fixed)

Opened October 31, 2007 07:52PM UTC

Closed April 28, 2008 09:14PM UTC

Last modified May 13, 2008 05:44PM UTC

fix() in event propagation is slow

Reported by: olau Owned by:
Priority: major Milestone: 1.2.4
Component: event Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:
Description

The fix() function called when an event is propagated deep copies the event to be able to set a few attributes. Unfortunately, the event object is quite large so this is really expensive for events like mousemove. On my 950 MHz PIII wiggling the mouse when an empty callback is set with mousemove() uses up 100% of the CPU time in Firefox.

There's a longer discussion on the mailing list here: http://groups.google.com/group/jquery-dev/browse_thread/thread/cc768c85d5514098

I've tried shallow copying the event with "for (v in originalEvent) event[v] = originalEvent[v];", but it's still slow.

The only solution I can think of is to copy a couple of documented standard values from the event object, normalizing them as needed, and then let people access the browser event object with an originalEvent field. If you can tell me which values to copy, I'd be happy to supply a patch.

Attachments (2)
  • 1871.diff (0.9 KB) - added by davidserduke November 16, 2007 02:12AM UTC.

    possible patch

  • jquery_test.html (1.0 KB) - added by davidserduke November 16, 2007 02:18AM UTC.

    used with FireFox and FireBug profiling to test mousemove event speed

Change History (5)

Changed November 16, 2007 02:18AM UTC by davidserduke comment:1

This patch uses Ariel Flesler's idea (posted in the above jquery-dev thread noted above) of prototype inheritance to clone the event node when possible instead of using extend(). It falls back to extend() when/if it fails like it seemed to do in my IE7 tests.

There are all sorts of possible side effects but it definitely sped up the event code during mousemove in my limited tests.

Changed November 16, 2007 03:30PM UTC by davidserduke comment:2

Unfortunately metaKey will be changed in the event when the ctrl key is held down. So this fix to speed can cause a JS error in that case.

Changed December 10, 2007 08:57PM UTC by nostrademons comment:3

If the issue is read-only properties, how about assigning the new

custom properties *first* and then setting the new event's prototype

afterwards. The new event is just a normal empty JavaScript object,

then, so it shouldn't run into any issues with read-only errors on

assignment. Then you could set the prototype chain as the last

operation in the function, which'll make sure that the returned object

returns the original object's values for anything that hasn't been

fixed up. It seems like this will work on any browser that conforms

to the ECMAScript standard for assignment & prototype access.

Changed April 28, 2008 09:14PM UTC by brandon comment:4

resolution: → fixed
status: newclosed

This should be addressed in Rev. [5344].

Changed May 13, 2008 05:44PM UTC by flesler comment:5

milestone: 1.2.21.2.4