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

Equivalence, invertable transformation, and size optimization of Wasm binaries #184

Open
poemm opened this issue Mar 16, 2019 · 4 comments

Comments

@poemm
Copy link
Contributor

poemm commented Mar 16, 2019

Implementations may wish to transform Wasm binaries to a form which is convenient (metered form, instantiated form, etc). If such transformations were invertible, then the original binary could be recovered and not stored.

There is an equivalence of Wasm binaries up to the LEB 128 encoding of integers. Thankfully, each integer seems to have a unique shortest LEB 128 encoding which is trivial to encode/decode. So this is a proposal to require integers to be in their shortest LEB 128 form. Shortest form is a major size optimization for Wasm binaries.

Another equivalence is encoding of local variable types. If consecutive local variables are of the same type, then a multiplicity notation can be used. So this is a proposal to require using this multiplicity notation whenever possible. Using multiplicity notation is a size optimization for Wasm binaries.

The above proposed requirements are already useful as size optimizations, but also allow more invertible transformations of code sections, which are often the longest sections.

A curious mind may notice that if one proves that they know all equivalences, then perhaps they can define a canonical form for Wasm binaries. Such a canonical form may be very useful. Please let me know if anyone is interested in this.

@cdetrio
Copy link
Contributor

cdetrio commented Mar 16, 2019

see also #97

@poemm
Copy link
Contributor Author

poemm commented Apr 10, 2019

Another equivalence is removal of opcodes after br, br_table, unreachable, or return. Anything after these opcodes will never execute, so it can be removed without changing behaviour of the Wasm module.

@lrettig
Copy link
Member

lrettig commented Apr 15, 2019

Could these transformations/compressions be run by chisel?

@poemm
Copy link
Contributor Author

poemm commented Apr 15, 2019

Could these transformations/compressions be run by chisel?

Yes.

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

No branches or pull requests

3 participants