Skip to content

Data from Binaryen implementation #21

Description

@tlively

Support for opportunistically emitting compact imports has landed in Binaryen: WebAssembly/binaryen#8926. Binaryen is just opportunistically and greedily emitting compact imports whenever it sees two imports in a row that have the same module and type or just the same module. It's not reordering imports to try to take advantage of compact imports at all.

I took a look at how compact imports affect the sizes of example programs from 4 different toolchains. The compact-imports and no-compact-imports modules were both run through the same Binaryen pipeline because Binaryen can change module sizes slightly even without running any optimizations. This makes it a more apples-to-apples comparison.

Here's the command I used to produce the files:

for w in java clang dart kotlin; do wasm-opt -O1 -all --disable-compact-imports ${w}.wasm --generate-stack-ir --optimize-stack-ir -o ${w}-no-ci.wasm && wasm-opt -O1 -all ${w}.wasm --generate-stack-ir --optimize-stack-ir -o ${w}-ci.wasm && brotli -9 < ${w}-no-ci.wasm > ${w}-no-ci.wasm.br && brotli -9 < ${w}-ci.wasm > ${w}-ci1.wasm.br; done

I ran the same command again with the logic for emitting encoding 2 (where both module name and externtype are shared) commented out to produce the *-ci1 results.

Here's the raw data:

 3964129 java-no-ci.wasm
 1045621 java-no-ci.wasm.br
 3935537 java-ci1.wasm
 1044310 java-ci1.wasm.br
 3881021 java-ci.wasm
 1037808 java-ci.wasm.br 

32123330 clang-no-ci.wasm
 8706737 clang-no-ci.wasm.br
32122969 clang-ci1.wasm
 8703684 clang-ci1.wasm.br
32122969 clang-ci.wasm
 8703684 clang-ci.wasm.br

 5335989 dart-no-ci.wasm
 1584270 dart-no-ci.wasm.br
 5327196 dart-ci1.wasm
 1584533 dart-ci1.wasm.br
 5327194 dart-ci.wasm
 1584406 dart-ci.wasm.br

 7179987 kotlin-no-ci.wasm
 1403186 kotlin-no-ci.wasm.br
 7174215 kotlin-ci1.wasm
 1403456 kotlin-ci1.wasm.br
 7174232 kotlin-ci.wasm
 1403343 kotlin-ci.wasm.br

And here are the takeaways:

Language Encoding 1 savings Additional encoding 2 savings Encoding 1 savings (compressed) Additional encoding 2 savings (compressed)
Java 28592 (0.72%) 54516 (1.39%) 1311 (0.13%) 6502 (0.62%)
Clang 361 (0.001%) 0 (0.0%) 3053 (0.04%) 0 (0.0%)
Dart 8793 (0.16%) 2 (0.0%) -263 (-0.02%) 127 (0.01%)
Kotlin 5772 (0.08%) -17 (-0.0%) -270 (-0.02%) 113 (0.01%)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions