shazow / whatsabi

Extract the ABI (and resolve proxies, and get other metadata) from Ethereum bytecode, even without source code.
https://shazow.github.io/whatsabi/
MIT License
1.07k stars 77 forks source link

ethers.js -> ox #153

Closed shazow closed 2 weeks ago

shazow commented 2 weeks ago

Closes #151

shazow commented 2 weeks ago

This increases the bundle 15.34 kb -> 23.61 kb (54%). Pretty substantialy, need to decide if it's worth it.

Before:

  lib.esm/index.js
  Size limit: 20 kB
  Size:       15.34 kB with all dependencies, minified and gzipped

  lib.cjs/index.js
  Size limit: 165 kB
  Size:       163.64 kB with all dependencies, minified and gzipped

After:

  lib.esm/index.js
  Package size limit has exceeded by 3.62 kB
  Size limit: 20 kB
  Size:       23.61 kB with all dependencies, minified and gzipped

  lib.cjs/index.js
  Package size limit has exceeded by 24.09 kB
  Size limit: 165 kB
  Size:       189.09 kB with all dependencies, minified and gzipped

@jxom Am I doing anything obviously wrong here?

jxom commented 2 weeks ago

Try import from ox/* instead of the root namespace. E.g. import * as Abi from ‘ox/Abi’, etc. Let me know if that doesn’t work and I can have a deeper look.

shazow commented 2 weeks ago

@jxom Updated in 4be0a081260b37fe419b87eb7d506f4a6e39d9b1, cjs bundle is smaller now, but esm is still roughly the same.

  lib.esm/index.js
  Package size limit has exceeded by 3.18 kB
  Size limit: 20 kB
  Size:       23.18 kB with all dependencies, minified and gzipped

  lib.cjs/index.js
  Size limit: 165 kB
  Size:       31.43 kB with all dependencies, minified and gzipped
jxom commented 2 weeks ago

Ah, found the culprit. Looks like these guys are affecting the tree-shaking process. Going to refactor things a bit to fix.

shazow commented 2 weeks ago

Thanks for investigating 🙏

jxom commented 2 weeks ago
  lib.esm/index.js
  Size limit: 20 kB
  Size:       14.04 kB with all dependencies, minified and gzipped

  lib.cjs/index.js
  Size limit: 165 kB
  Size:       31.36 kB with all dependencies, minified and gzipped

wooo, releasing new version now

jxom commented 2 weeks ago

Can you try update to ox@0.2.0?

jxom commented 2 weeks ago

Seems reasonably faster too.

 ✓ src/selectors.bench.ts (2) 1218ms
   ✓  (2) 1216ms
     name                                  hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · selectorsFromBytecode (ox)      2,273.48  0.3985  1.3748  0.4399  0.4401  0.6035  0.7232  1.0234  ±0.68%     1137   fastest
   · selectorsFromBytecode (ethers)    898.17  1.0256  1.6729  1.1134  1.1266  1.3229  1.3568  1.6729  ±0.45%      450

 BENCH  Summary

  selectorsFromBytecode (ox) - src/selectors.bench.ts >
    2.53x faster than selectorsFromBytecode (ethers)
shazow commented 2 weeks ago

Looking much better, thank you!

  lib.esm/index.js
  Size limit: 20 kB
  Size:       13.87 kB with all dependencies, minified and gzipped

  lib.cjs/index.js
  Size limit: 165 kB
  Size:       31.15 kB with all dependencies, minified and gzipped