next(Number) slowdown in Internet Explorer (6,7)

2 views
Skip to first unread message

vkojo...@gmail.com

unread,
May 23, 2007, 8:16:57 AM5/23/07
to Prototype: Core
With the latest prototype (1.5.1), the next() function (and probably
also prev() and the rest of the navigation function) cause a
tremendous slowdown in IE if they are used with the following syntax:
next(Number). From what I saw in the code, that translates to a
Selector with a '*' expression. Using next(null, 1) solves the
slowdown problem. Also, since this might be related,
getElementsByClassName is also very slow in this release.

Mislav Marohnić

unread,
May 23, 2007, 10:43:22 AM5/23/07
to prototy...@googlegroups.com
Possibly because those methods tend to DOM-extend every node on the way, and IE is the only browser that doesn't support native prototypes for DOM stuff. That should be avoided if possible, especially in getElementsByClassName.

Andrew Dupont

unread,
May 23, 2007, 10:40:45 PM5/23/07
to Prototype: Core
On May 23, 7:16 am, "vkojouha...@gmail.com" <vkojouha...@gmail.com>
wrote:

> With the latest prototype (1.5.1), the next() function (and probably
> also prev() and the rest of the navigation function) cause a
> tremendous slowdown in IE if they are used with the following syntax:
> next(Number). From what I saw in the code, that translates to a
> Selector with a '*' expression. Using next(null, 1) solves the
> slowdown problem.

This is troubling to me. I could've sworn I fixed this back when I
wrote the Selector code, but perhaps I just fixed it for the no-
arguments case and not the one-numeric-argument case. We'll address
this in 1.5.2.

> Also, since this might be related,
> getElementsByClassName is also very slow in this release.

Compared to which release? Care to post some benchmarks?

Cheers,
Andrew

Mislav Marohnić

unread,
May 24, 2007, 6:53:57 AM5/24/07
to prototy...@googlegroups.com
On 5/24/07, Andrew Dupont <goo...@andrewdupont.net> wrote:

> Also, since this might be related,
> getElementsByClassName is also very slow in this release.

Compared to which release? Care to post some benchmarks?

Andrew, it doesn't matter - getElementsByClassName tends to extend EVERY node in the document! If that isn't slow I don't know what is.

vkojo...@gmail.com

unread,
May 24, 2007, 10:59:38 AM5/24/07
to Prototype: Core

Sorry no benchmarks. That was just from the top of my memory. My
reason for putting 'in this release' in there was, that I didn't
notice any slowdowns when using getElementsByClassName in previous
releases (that were noticeable in this release, at least).
>
> Cheers,
> Andrew

Andrew Dupont

unread,
May 24, 2007, 7:49:37 PM5/24/07
to Prototype: Core
On May 24, 5:53 am, "Mislav Marohnić" <mislav.maroh...@gmail.com>
wrote:

> Andrew, it doesn't matter - getElementsByClassName tends to extend EVERY
> node in the document! If that isn't slow I don't know what is.

No, it doesn't. It extends only those nodes that match the class
name. I've personally spent quite a bit of energy to ensure that
getElementsByClassName performs as well as possible under the
circumstances, even in IE.

To the author: nothing has changed about the behavior of
getElementsByClassName since 1.5.0 final. It's *possibly* slower than
it was in 1.4 final (because of the cost of extending each node with
instance methods) -- but there have been some optimizations since 1.4,
too. If it seems slower to you in the future, try doing a side-by-side
comparison -- the Test.Unit framework packaged with the full source of
Prototype makes it easy to run benchmarks. That way we can get some
hard numbers.

Cheers,
Andrew

Tobie Langel

unread,
May 24, 2007, 8:15:43 PM5/24/07
to Prototype: Core
As a side note, the bigger the document you are working with is, the
slower the methods will be - obviously!


Mislav Marohnić

unread,
May 25, 2007, 4:10:56 AM5/25/07
to prototy...@googlegroups.com
On 5/25/07, Andrew Dupont <goo...@andrewdupont.net> wrote:

It extends only those nodes that match the class name.

It calls Element.hasClassName for every node, I hope we can agree on that. Now, let us remember what do methods from the Element namespace all have in common.

Hint: it has something to do with the first argument and the $ function.



Andrew Dupont

unread,
May 25, 2007, 11:32:50 AM5/25/07
to Prototype: Core
On May 25, 3:10 am, "Mislav Marohnić" <mislav.maroh...@gmail.com>
wrote:

> It calls Element.hasClassName for every node, I hope we can agree on that.
> Now, let us remember what do methods from the Element namespace all have in
> common.
>
> Hint: it has something to do with the first argument and the $ function.

Wow. That's a show-stopper. We need to fix this immediately.
(Apologies, Mislav.)

I worked on getElementsByClassName optimization about six months ago.
Sometime after that, it was changed to use Element.hasClassName --
presumably to stay DRY, but at a huge performance cost. I haven't
noticed this because I've given up getElementsByClassName almost
entirely -- in favor of $$ and getElementsBySelector.

Everyone on Core needs to understand: in IE, the cost of calling $ is
trivial in a single case, but in a loop it can be the difference
between instantaneous loading and a thirty-second freeze. That's why I
had to write new versions of all these functions for selector.js: I
needed functions that did not call $ or Element.extend, so that I
could be sure that no elements were extended until the final result
set.

Prototype isn't an optimize-first library, but every function that
queries the DOM needs every millisecond squeezed out of it. Since
there is no limit to the number of nodes on a page, there is no DOM
querying scenario that will not become a performance issue when taken
to its logical edge case (one needle, gigantic haystack). So we need
to be extra sensitive about this. Perhaps we should set some minimum
performance standards and run a couple benchmarks automatically as
part of the unit tests.

Once again to the original author: in light of this new information, $
$ should be faster than getElementsByClassName. This is both true and
ridiculous.

Cheers,
Andrew

Reply all
Reply to author
Forward
0 new messages