Skip to content

Optimization regression - excess function parameters are no longer optimized out #3193

@juj

Description

@juj

src.js

function foo(a, b) {
	console.log(a);
}
setTimeout(foo, 0); // pin a reference to foo so it does not get optimized out
foo("hello", "this_is_redundant");

Old Closure:

C:\emsdk\emscripten\incoming>java -jar third_party\closure-compiler_old\compiler.jar --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20171023
Built on: 2017-10-26 19:00
C:\emsdk\emscripten\incoming>java -jar third_party\closure-compiler_old\compiler.jar --js=src.js --js_output_file=out.js --compilation_level=ADVANCED_OPTIMIZATIONS

C:\emsdk\emscripten\incoming>type out.js
function a(b){console.log(b)}setTimeout(a,0);a("hello");

Closure optimized out the unnecessary "this_is_redundant" input string.

New Closure:

C:\emsdk\emscripten\incoming>java -jar third_party\closure-compiler\compiler.jar --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20181210
Built on: 2018-12-12 22:32
C:\emsdk\emscripten\incoming>java -jar third_party\closure-compiler\compiler.jar --js=src.js --js_output_file=out.js --compilation_level=ADVANCED_OPTIMIZATIONS

C:\code\emsdk\emscripten\incoming>type out.js
function a(b){console.log(b)}setTimeout(a,0);a("hello","this_is_redundant");

the optimization unfortunately no longer occurs, but "this_is_redundant" appears in the output.

In new Closure, the optimization does not occur in this case either:

src2.js

function foo(a) {
	console.log(a);
}
setTimeout(foo, 0); // pin a reference to foo so it does not get optimized out
foo("hello", "this_is_redundant");

although a warning is issued. In old Closure, this version was also optimized.

Curiously, new Closure does still optimize this variant of the code, where input parameters are reversed:

src3.js

function foo(a, b) {
	console.log(b);
}
setTimeout(foo, 0); // pin a reference to foo so it does not get optimized out
foo("this_is_redundant", "hello");

becomes

setTimeout(function(b,a){console.log(a)},0);console.log("hello");

so if a redundant parameter appears first, it does get optimized. But if it appears last, it no longer does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    internal-issue-createdAn internal Google issue has been created to track this GitHub issuetriage-doneHas been reviewed by someone on triage rotation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions