Bug Tracker

Modify

Ticket #2298 (closed bug: duplicate)

Opened 5 years ago

Last modified 5 years ago

global ajax events can be slow if lots of DOM elements

Reported by: davidserduke Owned by:
Priority: major Milestone: 1.3
Component: ajax Version: 1.2.2
Keywords: Cc:
Blocking: Blocked by:

Description

If there are lots of DOM elements, the global ajax events can be very slow. See related topic:

 http://groups.google.com/group/jquery-dev/browse_thread/thread/d189549ea277e7e6

I was thinking it might make sense to allow the coder to override the "global" nature of the ajax events by passing in a selector. Perhaps something like this:

$.ajaxSetup({ global:".global_event_elem" });

So instead of sending the global events to all elements it would just go to those specific ones in the selector.

I put together a possible patch that is completely untested.

Attachments

2298.diff Download (2.2 KB) - added by davidserduke 5 years ago.
untested patch (for the idea)

Change History

Changed 5 years ago by davidserduke

untested patch (for the idea)

comment:1 Changed 5 years ago by davidserduke

  • Component changed from core to ajax

comment:2 Changed 5 years ago by flesler

I think this can only be solved by improving global event triggering, or disabling it... My app got stuck for 40 seconds everytime I used $.ajax, because of these events.

comment:3 Changed 5 years ago by davidserduke

  • Milestone changed from 1.2.3 to 1.2.4

What did you think about the patch I created? Did you try it out? Of course, as I said, it is untested but the theory seems sound. It would allow "global" triggering to be specific to an expression. I'd think that would be sufficient for a large dom.

comment:4 Changed 5 years ago by flesler

IMO, we need to go backwards a bit, and keep an array of dom elements, for each event. So global triggering will be fast and focused. Those arrays can always be nullified on window.unload along with the global unbind that we now have. I don't want to be... negative, but I think that global triggering, like this, is completely useless and I personally evade it.

comment:5 Changed 5 years ago by davidserduke

Did you look at the patch? Why do you think it would be slow? Since you could put any selector in there you could even do something like

$.ajaxSetup({ global:"#globalajaxwatcher" });

I might be missing something but I don't follow your logic. Even if the DOM had thousands of elements I'd think that would be very fast.

comment:6 Changed 5 years ago by flesler

Ah, didn't understand it before. This approach forces the user to maintain a selector that matches all the dom elements that have ajax events bound, this already seems to go in the wrong direction.

IMO, if we're already storing dom elements (can leak) in the handlers (.elem), then keeping an array(or map) for each event seems to me like the best approach.

Also bear in mind, that this applies to any global triggering, not just ajax events.

comment:7 Changed 5 years ago by flesler

  • Status changed from new to closed
  • Resolution set to duplicate
  • Milestone changed from 1.2.4 to 1.3

#3107 improves this situation quite a bit.

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.