#2655 closed enhancement (fixed)
jQuery.event module optimizations
Reported by: | flesler | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.2.4 |
Component: | event | Version: | 1.2.3 |
Keywords: | event handle fix | Cc: | |
Blocked by: | Blocking: |
Description (last modified by )
Hi, here are a few modifications, that I think they will improve perfomance, and some make the code shorter, I'll explain them in case the reason for any change is not clear.
jQuery.event.fix
- The same event object, can't be fixed more than once (it happens when triggering.
jQuery.event.handle
- Removed the {} fallback when calling jQuery.event.fix, event.type is used in the next line, so IF you were to fall on the last case, the next line would alert 'event.type is not defined' seems like the 3rd case can't be reached.
- Avoided the need for Array.prototype.slice.call( arguments, 1 ) and args.unshift().
- Replaced args[0] for event when looping through the handlers, those were 2 array lookups per handler.
- Same for the namespace (parts).
- Simplified the val/ret part, ret is not needed and the code is now shorter.
- The forced call to preventDefault and stopPropagation is only checked and done once, after the loop.
Attachments (3)
Change History (9)
Changed 15 years ago by
Attachment: | handle-fix.diff added |
---|
comment:1 Changed 15 years ago by
Merged the first diff with 2 more changes.
jQuery.event.handle
- the copy of data and the handler to the event object, is only done if the handler is really going to be called, small change but it's correct and %0.001 faster.
- I saw the new function that's gets bound and saved into $.data('handle'), I simplified it a bit, it was kinda redundant :)
comment:2 Changed 15 years ago by
The third version adds 2 things.
- It caches the originally: !parts[0] && !event.exclusive in a variable. Those were 2 boolean casting and 2 boolean checks on each iteration.
- Instead of calling twice jQuery.data, an empty hash if used. It shorter and should be faster.
comment:4 Changed 15 years ago by
Description: | modified (diff) |
---|
comment:5 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Mostly applied in Rev [5276].
Just a couple of things different:
- The val returned from a handler can be a non-boolean value.
- An event must always be "fixed" in IE due to its global event object... at least that seems to be the case with my testing so far. I'm holding off on optimizing the event.fix method for lots more testing.
BTW ... I was seeing over 200% increase in performance of jQuery.event.trigger in IE. http://brandonaaron.net/jquery/tickets/2655/baseline-performance-test.html http://brandonaaron.net/jquery/tickets/2655/patched-performance-test.html
comment:6 Changed 15 years ago by
The val returned from a handler can be a non-boolean value
It says:
val = handler.apply( this, arguments ) '''!== false '''&& val;
That means that, unless it is explicitely false, it remains true. The val is not returned so it doesn't matter what it is, as long as it's not false... I might not be getting it, can you clarify me please ?
An event must always be "fixed" in IE
You can set event._fixed_ = null in IE, along with the event.target and the others.
BTW ... I was seeing over 200% increase in performance of jQuery.event.trigger in IE.
You mean with a change(s) I proposed ?
Changes