-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Suboptimal compilation for rest parameters #19182
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
Comments
Accepting PRs for the following optimizations (doesn't need to have all of them):
|
@Kingwl Are you still working on this issue? I'd like to take a swing at implementing some of the optimizations but don't want to duplicate work. |
@charlespierce No, I'm not on it, please feel free |
PR Opened with implementation of the first two bullet points: #20307 |
@ORESoftware please don't leave +1 comments; use the GitHub reactions feature (👍 on the issue). And there's certainly no point to multiple +1 comments on the same issue |
oh sorry I didn't realize I had already done that! yeah I haven't figured out how to use the reactions but I will now |
@RyanCavanaugh The PR for this issue #20307 is still awaiting review. I recognize it's a big diff, touching so many existing baselines, so is there anything I can do to help make it more manageable? |
i'd like to work on this (again) 😅 |
I think this is a duplicate of #498 |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
I think it is a different issue. The #498 is about TS generating code for unused rest parameter. This issue is about rest parameters that are used in some (possibly rare) code paths, but generated code is placed into all code paths, making it suboptimal. |
There is an TS/ES.next idiom for the JS
arguments
array:(...args: any[])
. But using it may produce suboptimal transpilation result, for example:produces following JavaScript (ES5) code:
Note that the
arguments
is copied to theargs
array immediately at the beginning of the function, before its real usage. This causes the code executed every time thedebug()
function is called, even if it is unnecessary.Expected behavior would be something more intelligent: either moving the
arguments
unrolling code closer to the usage place (may be tricky if there are multiple usage points), or usingArray.prototype.slice.call(arguments)
in-place without copying it into the temporaryargs
.Compare with Babel's transpilation result:
Note that here the copying was moved past the conditional expression and happens only when needed.
The text was updated successfully, but these errors were encountered: