Skip to main content

Bug Tracker

Side navigation

#3968 closed bug (worksforme)

Opened January 23, 2009 12:15AM UTC

Closed November 07, 2010 09:27PM UTC

ID-based lookup much slower on large pages

Reported by: C.Johnson Owned by: john
Priority: major Milestone: 1.3.2
Component: selector Version: 1.3.1
Keywords: getElementById, performance Cc:
Blocked by: Blocking:

In the Ajax-based commenting system at my site, when a user clicks a button to show any recently posted comments, part of the information that's returned from the Ajax call (in JSON form) is an array of objects that describes any recently edited or deleted comments that are already on the page. The Ajax callback function walks through this array and uses the ID attributes of modified comments to find them on the page and update their HTML accordingly.

Here's the code that performs this function:

for (var i = 0; i < delarray.length; i++) {

var dnum = $('#'+delarray[i].id).find('.cnum a:first-child').html();

$('#'+delarray[i].id).html(delarray[i].c).find('.cnum a:first-child').html(dnum);


The problem is that in version 1.3 and 1.3.1, this code executes <em>much</em> more slowly than it did in version 1.2.6, causing script timeout alerts in both IE6 and 7, and in Firefox. (In Safari it seems fine.)

The pages where the problem shows up contain a lot of comments, 500+ in many cases. But version 1.2.6 was imperceptibly fast, whereas 1.3.1 takes many seconds to get through the same loop, even if it only executes a few times.

Here's a page where you can see this slowdown, with the unminified version 1.3.1 installed on it; scroll to the bottom and click the 'new comments' button right above the comment submission form. In IE 6 or 7, you should have a long wait followed by the "script running too slowly" alert.

Attachments (0)
Change History (4)

Changed February 15, 2009 04:28PM UTC by dmethvin comment:1

Hi, can you post a test case that will stay up for a while? I took a quick look when the ticket was created, but now the test page has the "new comments" button disabled.

Changed February 18, 2009 02:46AM UTC by john comment:2

resolution: → invalid
status: newclosed

Changed February 22, 2009 06:40PM UTC by C.Johnson comment:3

resolution: invalid
status: closedreopened

Unfortunately, it's not resolved.

(Sorry about the test page not working, but the comment system disables new comments after 7 days.)

Here's another test page on which you can see the problem, with version 1.3.2:

Compare to the same page, using 1.2.6:

Changed November 07, 2010 09:27PM UTC by snover comment:4

resolution: → worksforme
status: reopenedclosed

1.4 includes a shortcut for ID lookups, so this should no longer be an issue.