Skip to content
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

How to remove no-op exported functions? #6506

Open
orsinium opened this issue Apr 17, 2024 Discussed in #6501 · 3 comments
Open

How to remove no-op exported functions? #6506

orsinium opened this issue Apr 17, 2024 Discussed in #6501 · 3 comments

Comments

@orsinium
Copy link

Discussed in #6501

Originally posted by orsinium April 15, 2024
Quite often, after all optimizations, wasm-opt leaves exported functions empty:

(module
  (type (func))
  (func (type 0)
    nop)
  (export "example" (func 0)))

Is there a way to tell wasm-opt that it is also safe to remove the exported functions if they are empty? I know for sure that the target runtime handles missed exports correctly.

Based on the discussion, there is currently no way to do so. Hence we decided that it's worth opening a proper feature request. The feature would help a lot with code optimization on both guest and host sides in situations when the host doesn't require the exported functions to be present.

@kripken
Copy link
Member

kripken commented Apr 17, 2024

Two possible ways to add such a feature:

  1. As a pass-option for RemoveUnusedModuleElements pass.
  2. Add a flag to wasm-metadce.
    In both cases the option would be something like "consider empty exports unused".

Which runtime is this, btw, that will safely ignore empty exports?

@orsinium
Copy link
Author

Which runtime is this, btw, that will safely ignore empty exports?

I'm building my own Rust runtime on top of wasmi. Knowing that the guest does not implement certain functions lets me do host-side optimizations. Similar to how pico-8 changes the frame rate to 60 FPS if _UPDATE60 function is provided.

Another example is wasm-4. It expects start and update exports both of which may be omitted:

@kripken
Copy link
Member

kripken commented Apr 18, 2024

I see, thanks for the info @orsinium !

With multiple VMs that could benefit here, this sounds very reasonable to add as an option.

Probably the first option I mentioned before (pass-option for RemoveUnusedModuleElements) is best. If someone has time to look into that but doesn't know where to start I can help out with guidance.

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

2 participants