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

Optimize binary size #38

Open
twifkak opened this issue Aug 27, 2021 · 2 comments
Open

Optimize binary size #38

twifkak opened this issue Aug 27, 2021 · 2 comments
Milestone

Comments

@twifkak
Copy link
Collaborator

twifkak commented Aug 27, 2021

The compiled cloudflare_worker wasm is currently around 1.2MB. The opt-level and lto tricks didn't reduce that. It's clearly possible to make small wasm binaries. Investigate the easiest change possible to make this one smaller.

The twiggy command identified table[0] as the main culprit. I think that might have to do with the use of JS callbacks? Judging by the MDN article and Lin Clark's article.

Things I didn't try:

  • get rid of format!
  • abort on panic
  • no_main
  • no_std

Articles I didn't read:

@twifkak twifkak added this to the v3+ milestone Aug 27, 2021
@twifkak
Copy link
Collaborator Author

twifkak commented Sep 24, 2021

I was wrong about table[0]. Useful output is available in a dev build, e.g.:

(cd cloudflare_worker; ~/.cache/.wrangler/wasm-pack-0.10.0/wasm-pack build --target no-modules --dev) && twiggy dominators cloudflare_worker/pkg/cloudflare_worker_bg.wasm | less

or likewise twiggy top

@antiphoton
Copy link
Collaborator

antiphoton commented Sep 24, 2021

The wasm is reduced from 1.2 MB to 993 KB by removing disabling the pem parsing code

 fn get_der(pem_text: &str, expected_tag: &str) -> Vec<u8> {
+    return vec![];
-    for pem in ::pem::parse_many(pem_text) {
-        if pem.tag == expected_tag {
-            return pem.contents;
-        }
-    }
     panic!("The PEM file does not contains the expected block");
 }

We could find an alternative pem parser that takes less than 240 KB.

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

2 participants