Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8401 (closed enhancement: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] getElementsByClassName shouldn't extend the whole document tree

Reported by: aorzecho Assigned to: mislav
Priority: high Milestone: 1.x
Component: Prototype Version: edge
Severity: normal Keywords: 1.5.2 ready 1.6
Cc:

Description

Hi,

I've been trying to optimize my app (using prototype151/scriptaculous), which works significantly slower on IE (no xpath) than on other browsers i tested

i've found that method getElementsByClassName causes extending every single element of the dom tree with Element methods, what seems quite costly especially for document node

that is because hasClassName method calls $ function on every argument and that causes extending (so we have 2 more func. for every dom node)

I suggest changing hasClassName to only call $ function when the typeof argument is string (attatched patch) - that gave me ~30% time save (IE) on initialization in my app

Attachments

patchClassName.diff (493 bytes) - added by aorzecho on 05/18/07 22:13:08.
gEBCN.diff (4.6 kB) - added by mislav on 06/10/07 20:37:07.
now with a twist

Change History

05/18/07 22:13:08 changed by aorzecho

  • attachment patchClassName.diff added.

05/19/07 00:32:34 changed by mislav

  • priority changed from normal to high.
  • severity changed from normal to minor.
  • summary changed from getElementsByClassName optimization to getElementsByClassName shouldn't extend the whole document tree.

Sweet penguins, you're right! We shall fix it immediately. While your proposal isn't exactly appropriate (it breaks consistency), we will still come up with something to speed this up.

Thanks for reporting!

05/29/07 20:51:54 changed by josh

  • summary changed from getElementsByClassName shouldn't extend the whole document tree to [PATCH] getElementsByClassName shouldn't extend the whole document tree.

05/29/07 21:06:21 changed by mislav

  • keywords set to 1.5.2.

06/10/07 17:35:54 changed by mislav

  • keywords changed from 1.5.2 to 1.5.2 ready.
  • owner changed from sam to mislav.
  • status changed from new to assigned.
  • severity changed from minor to normal.

Fixes #7853

06/10/07 20:37:07 changed by mislav

  • attachment gEBCN.diff added.

now with a twist

06/14/07 00:39:29 changed by Tobie

  • keywords changed from 1.5.2 ready to 1.5.2 ready 1.6.

06/17/07 22:26:50 changed by madrobby

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7053]) * Make document.getElementsByClassName match the WHATWG Web Applications 1.0 specification which was adopted in Firefox 3 (http://www.whatwg.org/specs/web-apps/current-work/#getelementsbyclassname). It now supports multiple class names given as an array or a space-separated list in a string. The method will only return the nodes that match all the class names. In browsers that implement the method natively it will not be overwritten. Closes #8401. [Mislav Marohnic]

06/18/07 18:16:56 changed by tobie

(In [7057]) Prevent document.getElementByClassName from extending the whole DOM tree in IE. Closes #8401.

06/19/07 20:59:17 changed by sam

(In [7065]) prototype: Make document.getElementsByClassName match a subset of the WHATWG Web Applications 1.0 specification which was adopted in Firefox 3 (http://www.whatwg.org/specs/web-apps/current-work/#getelementsbyclassname). It now supports multiple class names given as a whitespace-separated list in a string. Array argument is not supported. The method will only return the nodes that match all the class names. In browsers that implement the method natively it will not be overwritten. Closes #8401.

06/27/07 10:38:57 changed by madrobby

(In [7140]) Prototype: merges from form branch. Closes #5031, #5902, #7595, #8401, #8483, #8767. [Mislav Marohni?\196?\135, Tomas, Christophe Porteneuve, Jonathan Viney]