Side navigation
#6547 closed enhancement (invalid)
Opened May 07, 2010 05:05PM UTC
Closed January 14, 2011 07:55AM UTC
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
Attachments (0)
Change History (5)
Changed June 15, 2010 01:44AM UTC by comment:1
component: | unfiled → core |
---|
Changed November 03, 2010 08:51PM UTC by comment:2
keywords: | → speed each |
---|---|
milestone: | 1.4.3 → 1.5 |
priority: | → low |
status: | new → open |
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.
Changed November 03, 2010 08:53PM UTC by comment:3
Also, performance related enhancements are better accepted when they come along with a jsperf.com example. Thanks!
Changed December 30, 2010 03:01PM UTC by comment:4
owner: | → 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.
Changed January 14, 2011 07:55AM UTC by comment:5
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!