Opened 13 years ago
Closed 12 years ago
#6547 closed enhancement (invalid)
jQuery.each has unnecessary property lookups which are a hindrance to performance
Reported by: | fitzgen | Owned by: | fitzgen |
---|---|---|---|
Priority: | low | Milestone: | 1.5 |
Component: | core | Version: | 1.4.2 |
Keywords: | speed each | Cc: | |
Blocked by: | Blocking: |
Description
Hello jQuery!
I improved the performance of $.each while iterating over objects by storing object[ name ] in a local variable in the loop.
I ran the following to show myself that it was in fact faster with the local variable:
<html> <head></head> <body> <script type="text/javascript" src="jq-before.js" ></script> <script type="text/javascript"> var time = (new Date).valueOf(); var obj = { foo: 1, bar: 2, baz: 3, bang: 4, quux: 5 }; var i = 200000; while (i--) { $.each(obj, function () {}); } alert((new Date).valueOf() - time); </script> </body> </html>
FF 3.5 before: 4621 ms FF 3.5 after: 4186 ms
Chromium 5.0.391.0 before: 331 ms Chromium 5.0.391.0 after: 307 ms
The relevant commit is this one: http://github.com/fitzgen/jquery/commit/6e61c0ae03dbca67e3938fda6db61b297109777b
Thanks! jQuery is awesome!
Nick
Change History (5)
comment:1 Changed 13 years ago by
Component: | unfiled → core |
---|
comment:2 Changed 12 years ago by
Keywords: | speed each added |
---|---|
Milestone: | 1.4.3 → 1.5 |
Priority: | → low |
Status: | new → open |
comment:3 Changed 12 years ago by
Also, performance related enhancements are better accepted when they come along with a jsperf.com example. Thanks!
comment:4 Changed 12 years ago by
Owner: | set to fitzgen |
---|---|
Status: | open → pending |
gf3 posted his own results showing this was slower. Can you provide a jsperf.com example so we can test it across all browsers? Thanks.
comment:5 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | pending → closed |
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
A pull request is the fastest way to get this kind of stuff in core, but I'll push this through to the enhancement list.