Skip to content

Check full JS output for hello world #12806

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

Merged
merged 1 commit into from
Nov 18, 2020
Merged

Check full JS output for hello world #12806

merged 1 commit into from
Nov 18, 2020

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Nov 17, 2020

For the smallest hello world test, don't just check the output size
but check the full JS output matches the expectations.
That means that any change that touches those core lines of output
will need to rebaseline this test. However:

a) such changes deserve extra scrutiny
b) such changes should be few and far between
c) rebaselining is trivial (just run with EMTEST_REBASELINE=1)

Note that we do not compare the full wasm output since that is even
more fragile and can change with LLVM updates.


function e(a) {
if (!a) return "";
for (var k = a + NaN, b = a; !(b >= k) && f[b]; ) ++b;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line keeps making me sad every day.. google/closure-compiler#3223

var j = Math.sqrt;
var k = x.abort;
var l = NaN;
var m = Infinity;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yikes - This looks like something that could be low hanging to DCE? I wonder why Closure did not clean them.. :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@alon... What phase would we expect to clean this up? Is it something that closure should be able deal with?

Copy link
Member

Choose a reason for hiding this comment

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

I believe this is inside the wasm2js output. The JS optimizer doesn't normally run on that. We usually don't run a JS minifier on compiled code, as it could be massive. But you can try --closure 2 which I think does that.

An option is to handle this in wasm2js, that is, track what is needed and emit only that. Not sure how easy it would be.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But that about closure compiler itself.. .shouldn't it be able to eliminate these unused variables?

Copy link
Member

Choose a reason for hiding this comment

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

Closure would be able to do it., but closure does not run on the wasm2js output - except for --closure 2 (because, as I said, the compiled code can be massive).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah I see. Thanks. I wonder if we should be running with --closure 2 for these minimal codesize tests? @juj?

Copy link
Member

Choose a reason for hiding this comment

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

Because it falls down on huge files, I don't think we recommend --closure 2. But it would be good to investigate that, as maybe closure has gotten faster/uses less memory now?

@juj
Copy link
Collaborator

juj commented Nov 17, 2020

lgtm

@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 18, 2020

Are you OK with this @kripken ? If it proves too fragile we can always revert..

For the smallest hello world test, don't just check the output size
but check the full JS output matches the expectations.
That means that any change that touches those core lines of output
will need to rebaseline this test.  However:

a) such changes deserve extra scrutiny
b) such changes should be few and far between
c) rebaselining is trivial (just run with EMTEST_REBASELINE=1)

Note that we do not compare the full wasm output since that is even
more fragile and can change with LLVM updates.
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm, and let's see if this is annoying in practice.

var j = Math.sqrt;
var k = x.abort;
var l = NaN;
var m = Infinity;
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is inside the wasm2js output. The JS optimizer doesn't normally run on that. We usually don't run a JS minifier on compiled code, as it could be massive. But you can try --closure 2 which I think does that.

An option is to handle this in wasm2js, that is, track what is needed and emit only that. Not sure how easy it would be.

@sbc100 sbc100 merged commit 06692ff into master Nov 18, 2020
@sbc100 sbc100 deleted the full_output_check branch November 18, 2020 19:40
@juj
Copy link
Collaborator

juj commented Nov 24, 2020

It would actually be very good to run --closure 2 on one of these hello world wasm2js tests (but not all), so that we can verify that the generated output from wasm2js is Closure-safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants