Ticket #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: | |
| Blocking: | Blocked by: |
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
comment:2 Changed 3 years ago by SlexAxton
- Keywords speed each added
- Priority set to low
- Status changed from new to open
- Milestone changed from 1.4.3 to 1.5
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.
comment:3 Changed 3 years ago by SlexAxton
Also, performance related enhancements are better accepted when they come along with a jsperf.com example. Thanks!
comment:4 Changed 2 years ago by dmethvin
- Owner set to fitzgen
- Status changed from open to 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 2 years ago by trac-o-bot
- Status changed from pending to closed
- Resolution set to invalid
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!
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
