harmony-one / sdk

Javascript SDK of Harmony protocol.
MIT License
92 stars 43 forks source link

Remove encoding library bloat in @hamony-js/staking JavaScript SDK #108

Open klngrs opened 2 years ago

klngrs commented 2 years ago

When analyzing a recent build, I noticed that @harmony-js/staking is causing my bundle size to blow up due to the use of "text-encoding", which is now a deprecated library.

image

Reference: https://github.com/harmony-one/sdk/blob/3c7061887f25c6ba8def5af05672cdc4f44eb2dc/packages/harmony-staking/src/stakingTransaction.ts#L111

  1. I searched @harmony-js and it appears this library is only used in the staking sdk: https://github.com/harmony-one/sdk/search?q=%22text-encoding%22
  2. It looks like harmony is only using the UTF-8 encoder, since that's the default if no params are passed. https://github.com/harmony-one/sdk/blob/master/packages/harmony-staking/src/stakingTransaction.ts#L324

Given the above, I'd like to propose a leaner / tree-shakeable alternative to the deprecated "text-encoding"

chybisov commented 2 years ago

Came here to say exactly this. TextEncoder has native support a long time already and text-encoding was deprecated three years ago 😃

40% https://bundlephobia.com/package/@harmony-js/staking@0.1.56

image

@gupadhyaya @Renewwen @denniswon could you please look into this? Thank you!