Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reduce to deopted methods #3820

Merged
merged 2 commits into from
Oct 28, 2015
Merged

Conversation

jridgewell
Copy link
Collaborator

All of our currently deoptimized Underscore methods (pick, omit, invoke, without, and difference) change behavior based on the number of arguments pass to the call. This both adds reduce (and friends).

Supersedes (and incorporates) #3810.

@@ -68,6 +68,9 @@
// form param named `model`.
Backbone.emulateJSON = false;

// A cached regex to detect if the Underscore function contains the `arguments`
// keyword.
var containsArguments = /arguments/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to be /\barguments\b/, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@akre54
Copy link
Collaborator

akre54 commented Oct 7, 2015

This is a little gross but so is most of the perf rain dancing we're doing around those parts.

@akre54
Copy link
Collaborator

akre54 commented Oct 7, 2015

explicitly deopts any method that depends on arguments from falling through the cracks

Do we really need to do this though?

@just-boris
Copy link
Contributor

That is need because raw underscore methods behave so.
Why optimisation of reduce-family methods matters? This methods are applied for collection once per time and are not called so often

@jridgewell
Copy link
Collaborator Author

Do we really need to do this though?

Necessarily, no. But'll it catch our screw-ups next time. And it might increase interop with underscore-like libraries that use arguments for other reasons.

@akre54
Copy link
Collaborator

akre54 commented Oct 21, 2015

underscore-like libraries that use arguments for other reasons

The only library this could refer to is Lo-dash. And afaik he doesn't do anything with arguments. Unless I'm mistaken?

@jridgewell
Copy link
Collaborator Author

The only library this could refer to is Lo-dash.

Not specifically, this could be any handwritten library.

And afaik he doesn't do anything with arguments. Unless I'm mistaken?

I think lodash is pretty in-line with underscore on the functions Backbone uses.

@jridgewell
Copy link
Collaborator Author

Anyone else object?

@jridgewell jridgewell added the bug label Oct 27, 2015
@jridgewell jridgewell mentioned this pull request Oct 27, 2015
10 tasks
@@ -1166,8 +1173,8 @@
// Underscore methods that we want to implement on the Collection.
// 90% of the core usefulness of Backbone Collections is actually implemented
// right here:
var collectionMethods = { forEach: 3, each: 3, map: 3, collect: 3, reduce: 4,
foldl: 4, inject: 4, reduceRight: 4, foldr: 4, find: 3, detect: 3, filter: 3,
var collectionMethods = { forEach: 3, each: 3, map: 3, collect: 3, reduce: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you separate out these changes from the toString check? These should definitely get merged in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

All of our currently deoptimized Underscore methods (`pick`, `omit`,
`invoke`, `without`, and `difference`) change behavior based on the
number of arguments pass to the call. This both adds `reduce` (and
friends).

Supersedes (and incorporates) jashkenas#3810.
jridgewell added a commit that referenced this pull request Oct 28, 2015
Deopt Underscore methods that change on arguments
@jridgewell jridgewell merged commit 569f07e into jashkenas:master Oct 28, 2015
@jridgewell jridgewell deleted the reduce-deopt branch October 28, 2015 14:36
@jridgewell jridgewell changed the title Deopt Underscore methods that change on arguments Add reduce to deopted methods Oct 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants