<snip>
for (i=0; i < 4000; i++) {
var el = document.createElement("div");
el.className = "dot";
document.body.appendChild(el);
Event.observe(el, 'mouseover', function(e) { Element.setStyle
(Event.element(e), {background: "#00FF00"}); }.bindAsEventListener
(this), false);
}
</snip>
Given your "test", how do you know the slowdown is with
Event.observe, and not document.createElement (which _is_ slow)?
HTMLElement.clone is faster than document.createElement (which is
horrendously slow on IE); using innerHTML is an order of magnitude
faster than both. [1]
In addition to how you're creating the element, you're also causing a
bit of slowdown (and additional memory use) by creating an anonymous
function on each iteration, and binding on each iteration (which
creates anonymous closures) rather than once and caching the result.
e.x.
var f = function (e) {Event.element(e).setStyle({background:
"#00ff00"});}.bindAsEventListener(this);
for (i = 0; i < 4000; i++) {
// ...
Event.observe(el, 'mouseover', f);
}
If you want to prove Event.observe is slow in IE, you'll need to
write a (much) better test.
TAG
1. http://www.quirksmode.org/dom/innerhtml.html
On Aug 8, 2007, at 10:22 PM, [EMAIL PROTECTED] wrote:
>
> Hi all,
>
> I have an application that relies heavily on Event.observe, but I'm
> finding that in IE (tested mostly in 6), it is about 18 times slower.
> For me, this adds about six seconds to every action on my app for
> Internet Explorer users, and I have to figure out a workaround..
>
> Here's a quick code sample on my website that demos what I'm referring
> to:
>
> http://igargoyle.com/tests/ie_proto_event_observe_is_slower/
>
> Hope you can help!
>
> Thanks,
> Tom Longson
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---