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
Dead-code elimination of unused default parameters #4466
Labels
Comments
Hi, sorry for the silence. I think this is actually an interesting idea and while it is quite non-trivial, I did some work in #4498 which should make this possible. You can already try this out, there are just some small things I want to polish. |
@lukastaegert wow, fantastic! Thanks so much for working on this! Looking forward to seeing the PR land 👍 |
This was referenced May 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Use Case
I maintain Libauth, a library that offers WebAssembly crypto implementations (
ripemd160
,sha1
,sha256
,sha512
, andsecp256k1
). As a pure ESM library, Libauth can asynchronously instantiate each WASM implementation internally, exporting simple interfaces that behave like collections of JS-only functions (with better performance). Many of Libauth's exported functions also use one of these built-in WASM instances as a default parameter. For example,decodeBase58Address
has the definition:Most applications can simply call
decodeBase58Address(address)
to automatically use the default, WASM-basedsha256
implementation (internalSha256
).However, applications that already have another
sha256
implementation can provide that implementation as the second parameter:decodeBase58Address(address, mySha256Implementation)
. In this case, the default parameter (internalSha256
) is dead code and should be possible to eliminate from the application's bundle, saving hundreds of KBs from those bundles.Feature Proposal
During dead-code elimination/tree shaking, default parameters that aren't used by the bundle can be removed.
For this simple example:
module.js
:app.js
:The produced bundle should include only:
A detailed example (testing with all known bundlers) is available at this repo: https://github.com/bitjson/shake-default-params
The text was updated successfully, but these errors were encountered: