Ticket #10417 (closed feature: fixed)
Remove second arg from setTimeout calls (WAS jQuery.later)
| Reported by: | gnarf | Owned by: | gnarf |
|---|---|---|---|
| Priority: | low | Milestone: | 1.9 |
| Component: | core | Version: | git |
| Keywords: | 1.9-discuss | Cc: | |
| Blocking: | Blocked by: |
Description (last modified by gnarf) (diff)
We are starting to use more and more setTimeout( fn, 0 ); calls around our code base. I think now that there is also a setImmediate and there is also the postMessage that we should probably try to take advantage of these.
I would like to propose a jQuery.later( fn ) that wraps the "best" possible function here.
Change History
comment:5 Changed 20 months ago by dmethvin
- Priority changed from undecided to low
- Status changed from new to open
comment:7 Changed 18 months ago by jzaefferer
- Description modified (diff)
-1, There is no reason why this needs to depend on jQuery apart from bundling it.
comment:8 Changed 18 months ago by jaubourg
+1, not only does it make sense, it should also save some size.
comment:9 Changed 18 months ago by dmethvin
- Description modified (diff)
+1, It's small and we can use it internally, so yeah.
comment:10 Changed 18 months ago by mikesherov
- Description modified (diff)
+1, mostly fluff, but honestly, I'm personally sick of setTimeout( fn, 0). Let's do it.
comment:12 Changed 18 months ago by timmywil
- Description modified (diff)
-1, I don't think it's worth it
comment:13 Changed 18 months ago by hkdobrev@…
+1
It should save size and it would really prevent jQuery users from bad usage of setTimeout. For example many developers still do things like:
setTimeout("a lot of javascript in a string", ...)
comment:14 Changed 17 months ago by gibson042
I like the standardization and size neutrality (jquery.js has 5 instances of setTimeout( fn, 0..1 ), making this cost at most 12 bytes minified). But how about calling it jQuery.soon?
comment:15 Changed 17 months ago by gnarf
- Owner set to gnarf
- Status changed from open to assigned
- Description modified (diff)
comment:16 Changed 17 months ago by timmywil
I'll elaborate. I don't think this will give us the benefit we're looking for. In terms of performance, adding the function call will likely negate the benefit of using postMessage. The best performance always has the smallest stack. Besides, we're talking ops in the millions if comparing postMessage to setTimeout. As for setImmediate, it is not currently implemented in any browser except IE and will probably never become part of the spec. IE10 will implement it as msSetImmediate. I definitely don't think we should make use of that yet.
It is my understanding that the overall direction for browser vendors is to optimize for setTimeout(fn, 0) rather than add another function. We could very well be forcing the jQuery API to go in a direction we will regret later. I'm not saying never, but I suggest we table it.
comment:17 Changed 12 months ago by gnarf
Even if it doesn't wrap any other method, just having it wrap setTimeout( fn , 0 ) is nice
comment:18 Changed 11 months ago by dmethvin
We haven't done this yet in 1.8, but I'm also not seeing any place where it is going to save us anything in the current code. Thoughts? Should we push to 1.9 and discuss then?
comment:20 Changed 8 months ago by dmethvin
Thoughts about the benefits? The setTimeout implementation adds a relatively large delay but is not a lot of code. I'm on the fence about it now.
comment:21 Changed 8 months ago by gibson042
I'm neutral on this too, but +1 if it reduces size.
comment:22 Changed 7 months ago by mikesherov
+1, I'm with @gibson042 on this. If it's smaller, sure.
comment:23 Changed 7 months ago by rwaldron
+1, But we need to bikeshed on the naming
comment:24 Changed 7 months ago by gibson042
+1, if it reduces size
comment:25 Changed 7 months ago by anonymous
+1
comment:27 Changed 6 months ago by Oleg
- Status changed from assigned to closed
- Resolution set to fixed
Fix #10417. setTimeout w/o 2nd arg is jQuery.later! Close gh-1065.
Changeset: d41b983259042d3a07ae785c09f71c68d9ce7c3f
comment:28 Changed 4 months ago by dmethvin
- Summary changed from jQuery.later to Remove second arg from setTimeout calls (WAS jQuery.later)
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
