So my original code sample was based on my application, which happened to use bindAsEventListener(). I didn't know if that was potentially causing a major problem in IE6, but I still don't feel like I have a great solution to the problem. The problem isn't especially due to the DOM creation, I just did that to try it out (again, cool). Not being at a computer with IE6, I can't see if my new test is faster than I originally said, but there still is a *serious* slowdown when I do Event.observe on IE6, and I'm not sure how to improve it.
This is still a bit rough, but my code is here if you want to see the exact example: http://stage.whypaysticker.com/showroom/ Lines 744 - 755 of controller.js are the Event.observe calls (I was trying to replace them, hence the comments). I've been working on this for some time, but I'd love some senior feedback. Thanks, nym (been using this handle for many years) On Aug 9, 1:23 pm, Tom Gregory <[EMAIL PROTECTED]> wrote: > On Aug 9, 2007, at 1:26 PM, [EMAIL PROTECTED] wrote: > > > Also, since there are so many Tom's on this mailing list, just call me > > "nym". > > It's really a bit of an unusual experience for me. Family reunions > excepted, I've never come across as many Toms in one place. (And I > really was kidding about picking a name other than "Tom" ;) > > > Is this a (much) better test now? > > Yes. For starters your now better describing the test as "create and > observe" rather than just "observe", and are attempting to control > for creation. This is important, as your claim was based on > Event.observe. As you can see between your results in test2 and > test3, a good chunk of the variation was from element creation. (IE > is much faster on element creation using Prototype's method; Firefox > is marginally slower.) But, the test can still use some minor > improvement. You're still seeing some slowdown by binding on each > iteration (which is creating a unique closure each time), rather than > binding once and caching the result. > > i.e., not: > > for (i=0; i < 4000; i++) { > // ... > Event.observe(el, 'mouseover', changeColor.bindAsEventListener > (this), false); > // ... > > } > > ... but rather this, only creating the closure once: > > var f = changeColor.bindAsEventListener(this); > for (i=0; i < 4000; i++) { > // ... > Event.observe(el, 'mouseover', f, false); > // ... > > } > > By binding each time, you're creating another place that might be the > cause of significant slowdown. Actually, I'm not sure why you're > binding at all--this test doesn't need to. If it's just to ensure > the event gets passed to the callback, Event.observe already handles > that for you. > > e.g. > for (i=0; i < 4000; i++) { > // ... > Event.observe(el, 'mouseover', changeColor, false); > // ... > > } > > I don't expect enormous speedup from this change, but I do expect > noticeable speedup (which is not included in numbers, below). > > If you take the difference between average "creation" and average > "create+observe", you get an approximate time of Event.Observe. (This > may not be entirely accurate, but close enough.) Your test results > show IE may actually be __faster than Firefox__ w/ Event.observe: > (using your numbers, as I don't have IE): > > Firefox (avg("create+observe") - avg("create") = approx avg("observe")): > 3:318 - 0:745 = approx 2:573s. > > IE (avg("create+observe") - avg("create")= approx avg("observe")): > 2.636 - 0:734 = approx 1:902s. > > TAG > > P.S. You may also find this link of interest as you seek to optimize > your current app, which IIRC, is what prompted this test. It includes > loop optimization suggestion, including reverse loop counting, > unrolling, and Duff's Device:http://home.earthlink.net/~kendrasg/info/js_opt/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
