Skip to content

start function optimization #14

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

Closed
blooddy opened this issue Jan 14, 2018 · 12 comments
Closed

start function optimization #14

blooddy opened this issue Jan 14, 2018 · 12 comments

Comments

@blooddy
Copy link

blooddy commented Jan 14, 2018

function init():void {
}
init();

output

(module
 (type $v (func))
 (memory $0 1)
 (export "memory" (memory $0))
 (start $.start)
 (func $init (; 0 ;) (type $v)
  (nop)
 )
 (func $.start (; 1 ;) (type $v)
  (call $init)
 )
)

an unnecessary $.start function is created.
most likely this will automatically be corrected if you add inline function support (#12)

@dcodeIO
Copy link
Member

dcodeIO commented Jan 14, 2018

Yeah, the start function is automatically generated from all the top level statements. Running Binaryen's inlining pass will most likely optimize this away.

Once this PR lands in Binaryen, asc can support different optimization levels like -O3 etc., which then include inlining.

@dcodeIO dcodeIO mentioned this issue Jan 14, 2018
@MaxGraey
Copy link
Member

I think this can already be closed

@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

What' still happening, though, is that if the start function becomes empty after optimizations, it is not removed by the optimizer. Looks like:

  (func $start (type $v)
    nop
  )
  (start $start)

@MaxGraey
Copy link
Member

Sorry. I checked in WebAssembly Studio and this true. But in Assembleash I use this config:

 module.runPasses([ "trap-mode-clamp" ]);
 module.setOptimizeLevel(3);
 module.setShrinkLevel(2);

And this inlined perfectly. You can check

@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

Just checked: Try to compile just ; (EmptyStatement, emulates the rest of the body being optimized away) - this results in the empty start function mentioned above.

@MaxGraey
Copy link
Member

I try in my playground and this is result:

2018-02-28 17 38 49

@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

I see, yeah, the inlining works, but the start function is still there, though it could be removed.

@MaxGraey
Copy link
Member

MaxGraey commented Feb 28, 2018

But this is normal... or not? I thought start should be always present

@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

It is not required that it's there, so imho it should be removed. This is a Binaryen specific thing, of course.

@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

See: WebAssembly/binaryen#1449

@MaxGraey
Copy link
Member

Cool!

@dcodeIO
Copy link
Member

dcodeIO commented Mar 5, 2018

Alright, the last remaining bits should be fixed as well using latest Binaryen. Closing for good.

@dcodeIO dcodeIO closed this as completed Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants