Bug Tracker

Opened 15 years ago

Closed 13 years ago

#3968 closed bug (worksforme)

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:

Description

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.

http://littlegreenfootballs.com/weblog/weblogx.php?entry=32524

Change History (4)

comment:1 Changed 15 years ago by dmethvin

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.

comment:2 Changed 15 years ago by john

Resolution: invalid
Status: newclosed

comment:3 Changed 15 years ago by C.Johnson

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:

http://littlegreenfootballs.com/weblog/weblogx.php?entry=32855

Compare to the same page, using 1.2.6:

http://littlegreenfootballs.com/article/32855/comments

comment:4 Changed 13 years ago by snover

Resolution: worksforme
Status: reopenedclosed

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

Note: See TracTickets for help on using tickets.