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

Rename local variable arguments to args #14996

Merged
1 commit merged into from
Apr 5, 2017
Merged

Rename local variable arguments to args #14996

1 commit merged into from
Apr 5, 2017

Conversation

ghost
Copy link

@ghost ghost commented Apr 3, 2017

This may be affecting performance? CC @rbuckton

@RyanCavanaugh
Copy link
Member

Any measurements?

@@ -1411,16 +1411,16 @@ namespace ts {
if (callExpression.kind !== SyntaxKind.CallExpression) {
return false;
}
const { expression, arguments } = callExpression as CallExpression;
const { expression, arguments: args } = callExpression as CallExpression;
Copy link
Contributor

@yuit yuit Apr 4, 2017

Choose a reason for hiding this comment

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

Would it be better to just rename property in CallExpression? Also would this change should be applied to newExpression as well?

Copy link
Member

Choose a reason for hiding this comment

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

That would be a breaking change to API consumers.

@rbuckton
Copy link
Member

rbuckton commented Apr 4, 2017

@RyanCavanaugh there was a spike in the build-to-build performance tests associated with this change. Whether this was the direct cause I haven't yet determined. Regardless of the performance metrics, we should never shadow arguments with a local or reassign it. It deoptimizes the function in v8, and is an error in strict mode.

@ghost
Copy link
Author

ghost commented Apr 5, 2017

The PR that added this code was #14984 on April 3rd. The performance tester showed emit time spike after that commit, but this function is called by the binder and checker. In the time since, emit time has gone back down.
That link doesn't mention shadowing, just mutation. Can you verify that deoptimization is actually taking place?

@rbuckton
Copy link
Member

rbuckton commented Apr 5, 2017

@andy-ms the initial arguments binding is hoisted inside of a function. A "redeclaration" of arguments using var doesn't really do anything, as can be observed in node:

> function f() { var arguments; console.log(arguments.length); }
> f(); 
0
> f("a");
1

So any assignment to arguments, even with a variable initializer, is actually reassigning the initial arguments binding.

That said, I ran a javascript project through tsc with hydrogen tracing and didn't see any specific deoptimizations in this function. I still think its worth the change.

@ghost
Copy link
Author

ghost commented Apr 5, 2017

Ah, forgot we're compiling to ES5.

@ghost ghost merged commit bb8862f into master Apr 5, 2017
@ghost ghost deleted the args branch April 5, 2017 20:45
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants