Thanks Marcus, looking forward to seeing your code. --John
On Tue, Feb 24, 2009 at 9:20 PM, Marcus Pope <[email protected]> wrote: > > John- I don't have an account yet so I cannot post the diff. I'll > send you an email containing the diff, but it was really just a proof > of concept to ensure that my app would compile with the jquery lib > included. I haven't tested it yet and it's partly why I asked the > group about the situation. > > For anyone interested I basically added the following statement: " if > (!obj.hasOwnProperty(x)) continue; " to each for..in loop where obj & > x were the object & key values. In some cases I had to add brackets > to the for..in loop. > > After reading the attached discussions in the ticket you referenced > and doing a bit more research on the topic I decided to run some tests > on hasOwnProperty since everyone liked to say it would destroy > performance but provide no stats. As it turns out the performance hit > was about 5% when using hasOwnProperty and 2.5% when using > Object.prototype[x]. I'm not sure how often jQuery is iterating over > objects for any given application, but I can't imagine it's anywhere > close to 50% which means the overall impact on an application is > negligible. There are far easier ways to gain a percentage point > increase in performance in a web app than worrying about an if > statement in a for loop. > > According to my research there is also the problem of hasOwnProperty > not being supported in Safari 1.3 & IE5.0, but the prototype check is > supported and it's faster anyway. > > For my purposes I don't care so much about speed as I do about the > flexibility of my framework as my focus is on data mining and > automation on the internet which has performance issues orders of > magnitude greater than a few hundred milliseconds. But from the > research it looks like this has been a thorn in a few people's sides > so maybe there is a need to optimize further. In which case I'd go > with Yehuda Katz and optimize with a whitelist where you have full > control, and possibly with a blacklist and some checksum on the > object's prototype collection when you can't trust it. > > Andrea - as for modifying hasOwnProperty, I would expect that it be a > good thing to rely on that modification. If someone had modified that > function it would probably be for a very good purpose. I've done some > crazy machine learning algorithms based on the premise that I can > modify and extend the prototype of every object and being able to > isolate or selectively include certain keys as always being native to > the object could prove necessary. In that instance I would also want > jQuery to think they were part of the object as well, and if I didn't > I could modify my hasOwnProperty implementation to handle such a case. > > Anyway, the test results are below, and I'll send that email to your > gmail account John. Thanks for the quick reply! > > 500k "for..in" iterations > run on an idle, amd 1.8 ghz 1g memory system running xp, ie7 > > each test was run in a new instance of a browser > times are in milliseconds and do not include object construction > > Time with No Prototype Extension, Checking for hasOwnProp > 19297, 19141, 19140 > > Time with No Prototype Extension, No hasOwnProp > 18157, 18375, 18188 > > Time with 100 Prototype Extensions, no hasOwnProp > 18250, 18281, 18235 > > Time with 100 Prototype Extensions, checking for hasOwnProp > 19047, 19125, 19015 > > Time with 100 Prototype Extensions, checking Object.prototype > 18657, 18750, 18609 > > > On Feb 24, 3:45 pm, John Resig <[email protected]> wrote: >> Marcus - >> >> This is the current ticket that I'm tracking on the >> issue:http://dev.jquery.com/ticket/2721 >> >> I currently have it on the 1.4 roadmap - but if you already have a >> patch, I would love to see it (please attach it to the above ticket, >> as well) - perhaps we can get something landed sooner, rather than >> later. >> >> --John >> >> >> >> On Tue, Feb 24, 2009 at 4:04 PM, Marcus Pope <[email protected]> wrote: >> >> > Of the 4 total bugs found when searching for hasOwnProperty, each one >> > reports that jQuery doesn't support object prototype extensions >> > because of some factor. In the most recent case a bug was closed >> > invalid with the following explanation: >> >> > "jQuery does not support changes to Object.prototype. The additional >> > Object properties become visible to for-in loops and breaks any code >> > that uses them. " >> >> > After going through and editing the 30 or so references to unsafe >> > for..in loops I was able to compile my application which extensively >> > uses custom functions on the object prototype. I guess I'm confused >> > as to why this cannot (or will not) be integrated into the jquery >> > code. >> >> > I'll admit I'm not a jQuery expert, but I couldn't find any code using >> > inherited objects in the for..in iterations. Maybe it has something >> > to do with jquery pluggins. >> >> > Of course my solution is to modify the codebase every time a new >> > version is released, but this seems pointless if making the iterations >> > safe would resolve the problem altogether. >> >> > Just curious, any info welcome. >> >> > Thanks, >> > Marcus- Hide quoted text - >> >> - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" 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/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
