#10733 closed bug (fixed)
remove uses of jQuery.each in css module in favor of a for loop
Reported by: | mikesherov | Owned by: | mikesherov |
---|---|---|---|
Priority: | low | Milestone: | 1.7.1 |
Component: | css | Version: | 1.7 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
as far as I can tell, using $.each is monstrously slow compared to a regular for loop. See here: http://jsperf.com/for-loop-vs-each/6
In interest of performance, should we avoid using it internally when possible.
1.8?
Change History (20)
comment:1 Changed 12 years ago by
Component: | unfiled → misc |
---|---|
Keywords: | 1.8-discuss added |
Priority: | undecided → low |
Status: | new → open |
comment:2 Changed 12 years ago by
-1, I'm not against performance improvements, but we should balance performance with size, maintainability, and readability.
comment:3 Changed 12 years ago by
timmywil, to your point, there are only a few places where .each is used in actual function execution, and one of them is css.js. Can we change the title to REMOVE USES OF JQUERY.EACH INTERNALLY IN FAVOR OF A FOR LOOP WHEN IMPACTING FUNCTION EXECUTION
I'll adress each point for just that example: size: replacing jQuery.each with a for loop in getWH(), the code when gzipped and minified is one byte less. readability: is a for loop less readable than $.each? Maybe. maintainability: is a for loop less maintainable than $.each? Maybe. perf: no choice but to be faster, but I'll make a perf to prove it. It might be negligible.
If the perf is negligible and the savings is only 1 byte, than perhaps $.each is more readable enough to warrant not changing.
Thanks for the response.
comment:4 Changed 12 years ago by
@mikesherov: actually, I'd be in favor of the change in getWH. That is something that does get used a lot and possibly called many times per second in certain use cases.
comment:5 Changed 12 years ago by
Please feel free to present more spots you think we could benefit from this change. Changing my vote to +0, depending on the place.
comment:7 Changed 12 years ago by
So, it seems that .each is used mostly for function definition except for:
- effects.js:
- the .step() function when done to restore offset properties.
- the genFx function which seems to get called once per animation
- manipulation.js
- when eval'ing scripts in .domManip()
- css.js
- where I already mentioned
Seems like only in .css is worth it. Please change ticket name to reflect only in .css. I'll submit a perf and PR shortly.
comment:8 Changed 12 years ago by
Owner: | set to mikesherov |
---|---|
Status: | open → assigned |
Summary: | remove uses of jQuery.each internally in favor of a for loop → remove uses of jQuery.each in css module in favor of a for loop |
comment:10 Changed 12 years ago by
Not surprised that modern browsers are just fast. What about IE6, 7?
comment:11 Changed 12 years ago by
I don't have IE7 and IE6 on my laptop, anyone else willing to test it in IE7 and IE6 for me?
comment:12 Changed 12 years ago by
IE7 seems negligible. IE8 / safari / opera / and FF seem to have decent speed ups, on the the order of 10 - 20%.
I'll submit the PR, and leave it up to you guys on whether it's less maintainable or not.
comment:14 Changed 12 years ago by
@mikesherov say hello to your new BFF: http://www.browserstack.com
comment:16 follow-up: 18 Changed 12 years ago by
please close this ticket as the PR has been merged.
comment:17 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:18 Changed 12 years ago by
Replying to mikesherov:
please close this ticket as the PR has been merged.
Mike, use "Fixes #XXX" where XXX is the id of the ticket in your commit message next time and the ticket will be closed automagically ;)
comment:20 Changed 12 years ago by
Keywords: | 1.8-discuss removed |
---|---|
Milestone: | 1.8 → 1.7.1 |
OR, if dave used pulley... ;)
In that perf, you're still talking millions. I don't think we need to worry about the use of $.each defining functions and the like, but we should be concerned about the performance of the most commonly used functions (and I think this is already done internally for the most part).