Bug Tracker

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#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:
Blocked by: Blocking:

Description (last modified by gnarf)

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 (28)

comment:1 Changed 12 years ago by gnarf

Keywords: 1.8-discuss added

comment:2 Changed 12 years ago by gnarf

Description: modified (diff)

comment:3 Changed 12 years ago by Rick Waldron

neat!

comment:4 Changed 12 years ago by Rick Waldron

Component: unfiledcore

comment:5 Changed 12 years ago by dmethvin

Priority: undecidedlow
Status: newopen

comment:6 Changed 12 years ago by sindresorhus

#10936 is a duplicate of this ticket.

comment:7 Changed 12 years 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 12 years ago by jaubourg

+1, not only does it make sense, it should also save some size.

comment:9 Changed 12 years ago by dmethvin

Description: modified (diff)

+1, It's small and we can use it internally, so yeah.

comment:10 Changed 12 years ago by mikesherov

Description: modified (diff)

+1, mostly fluff, but honestly, I'm personally sick of setTimeout( fn, 0). Let's do it.

comment:11 Changed 12 years ago by Rick Waldron

Description: modified (diff)

+1, Seems highly useful

comment:12 Changed 12 years ago by Timmy Willison

Description: modified (diff)

-1, I don't think it's worth it

comment:13 Changed 12 years 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 12 years 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 12 years ago by gnarf

Description: modified (diff)
Owner: set to gnarf
Status: openassigned

comment:16 Changed 12 years ago by Timmy Willison

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 11 years 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 years 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:19 Changed 11 years ago by gibson042

Keywords: 1.9-discuss added; 1.8-discuss removed

comment:20 Changed 11 years 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 11 years ago by gibson042

I'm neutral on this too, but +1 if it reduces size.

comment:22 Changed 11 years ago by mikesherov

+1, I'm with @gibson042 on this. If it's smaller, sure.

comment:23 Changed 11 years ago by Rick Waldron

+1, But we need to bikeshed on the naming

comment:24 Changed 11 years ago by gibson042

+1, if it reduces size

comment:25 Changed 11 years ago by anonymous

+1

comment:26 Changed 11 years ago by mikesherov

Milestone: None1.9

comment:27 Changed 11 years ago by Oleg

Resolution: fixed
Status: assignedclosed

Fix #10417. setTimeout w/o 2nd arg is jQuery.later! Close gh-1065.

Changeset: d41b983259042d3a07ae785c09f71c68d9ce7c3f

comment:28 Changed 11 years ago by dmethvin

Summary: jQuery.laterRemove second arg from setTimeout calls (WAS jQuery.later)
Note: See TracTickets for help on using tickets.