paulmillr / scure-base

Secure, audited & 0-deps implementation of bech32, base64, base32, base16 & base58
https://paulmillr.com/noble/#scure
MIT License
106 stars 13 forks source link

Tree shaking #14

Closed jeetiss closed 1 year ago

jeetiss commented 1 year ago
paulmillr commented 1 year ago

what if we make chain etc side effects free? Would this work as well?

jeetiss commented 1 year ago

i'm not sure that it will gain some improvements here but it is safe so we can

paulmillr commented 1 year ago

I've meant different thing: can we remove PURE annotation from variables if we have __NO_SIDE_EFFECTS__ annotation in chain?

jeetiss commented 1 year ago

__NO_SIDE_EFFECTS__ annotation is supported only by rollup and esbuild. terser and uglifyjs don't support it. google closure compiler work with @nosideeffects but not __NO_SIDE_EFFECTS__ I think it is too early to migrate to this annotation, it should be adopted well before

I like __NO_SIDE_EFFECTS__ approach more. it's less noisy, hope it would be implemented by other minifiers in some days

paulmillr commented 1 year ago

Got it.

Why does support by minifiers matter though? The build is usually done by bundlers first, because minifiers lack some features. After that, minifier does a second pass, on a bundled code.

jeetiss commented 1 year ago

I found this thread by Ivan Akulov https://twitter.com/iamakulov/status/1353650608750825472

tldr;

webpack still relay that dead code elimination (and tree-shaking) would be done by terser (or other minifier) so it is important

paulmillr commented 1 year ago

I've just tested esbuild and the PURE annotations don't work.

import { base64url } from '@scure/base';
base64url.encode('a')
{
  "name": "build",
  "private": true,
  "version": "1.0.0",
  "main": "input.js",
  "type": "module",
  "devDependencies": {
    "@scure/base": "..",
    "esbuild": "0.17.19"
  },
  "scripts": {
    "build": "npx esbuild --bundle input.js --outfile=scure-base.js --global-name=scureBase"
  }
}

Exported properties are still kept. Any ideas why?

paulmillr commented 1 year ago

16