google / google/closure-compiler

Missed inlining opportunity when function contains math

Open
#1,878 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Closure Compiler isn't currently able to consider the results of precomputing math when deciding whether to inline a function (when the function body is longer than a minified function call).

``` javascript
function times5(x) {
return x + x + x + x + x;
}
alert(times5(2) + times5(3) + times5(4) + times5(5) + times5(6) + times5(7));
```

Possible result were the function inlined:

``` javascript
alert(135)
```

Actual result:

``` javascript
function a(b){return b+b+b+b+b}alert(a(2)+a(3)+a(4)+a(5)+a(6)+a(7));
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.