Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Reduce bundle-size of contracts-* packages #2330

Merged
merged 25 commits into from
Nov 12, 2019

Conversation

fabioberger
Copy link
Contributor

@fabioberger fabioberger commented Nov 11, 2019

Description

This PR addresses the issue of the @0x/contracts-* packages bundle sizes with several refactors:

  1. Add a .npmignore in each package that excludes everything from publish except the lib/src dir (until now we've been publishing everything: https://unpkg.com/browse/@0x/[email protected]/).
  2. Give (1), code within the test dir is not published. Because of this, any exports from this dir that we still want exported were moved to the src dir.
  3. Blanket dir exports were removed from index.ts files. We want our public interface to be as small and concise as possible. These were replaced with specific imports. Protocologists, please develop a sensitivity to bundle size and what constitutes the public interface of a package 🙏 .
  4. In order to prevent publishing artifacts and wrappers for every mixin, interface and test contract, @0x/contracts-gen now generates all theartifacts and wrappers into the test dir of each package. Each package.json now contains a publicInterfaceContracts config where we then pick which contracts we want to expose via the public interface. These contract artifacts/wrappers then get copied from the test dir to the src dir as part of the build process.

This refactor was made more difficult due to the prolific use of import * from '../src' (imports from index.ts) within packages. Please stop using this convention as it makes future refactors harder. It doesn't take that much work to explicitly import like one does with external imports.

Results

@0x/contracts-exchange

Before:

npm notice name:          @0x/contracts-exchange
npm notice version:       2.2.0-beta.1
npm notice filename:      0x-contracts-exchange-2.2.0-beta.1.tgz
npm notice package size:  6.7 MB
npm notice unpacked size: 72.5 MB
npm notice shasum:        986383da082765999c4a48377cfa404d73a92811
npm notice integrity:     sha512-9VD+ekw5gJ8kU[...]eTAEbNu4EhD6g==
npm notice total files:   757

After:

npm notice name:          @0x/contracts-exchange
npm notice version:       2.2.0-beta.1
npm notice filename:      0x-contracts-exchange-2.2.0-beta.1.tgz
npm notice package size:  261.8 kB
npm notice unpacked size: 3.2 MB
npm notice shasum:        851cef55f3f006c0bc17fe8f2cc7660a004d493f
npm notice integrity:     sha512-wewtcutvVc9tN[...]qZf2tGPDjtu8A==
npm notice total files:   69

@0x/contracts-asset-proxy

Before:

npm notice name:          @0x/contracts-asset-proxy
npm notice version:       2.3.0-beta.1
npm notice filename:      0x-contracts-asset-proxy-2.3.0-beta.1.tgz
npm notice package size:  1.6 MB
npm notice unpacked size: 13.8 MB
npm notice shasum:        f75727770147ac24f172f97e6dab3a8c13720980
npm notice integrity:     sha512-dZ3wMzYrEeZWF[...]ySfG7/nNheojA==
npm notice total files:   408

After:

npm notice name:          @0x/contracts-asset-proxy
npm notice version:       2.3.0-beta.1
npm notice filename:      0x-contracts-asset-proxy-2.3.0-beta.1.tgz
npm notice package size:  318.6 kB
npm notice unpacked size: 2.5 MB
npm notice shasum:        ee1e50d0470345d6624c367e5976e8c35c90ecab
npm notice integrity:     sha512-NfvYnjHrYJ2mm[...]ljSQmxARVT7rw==
npm notice total files:   99

All packages experienced close to an order of magnitude size reduction.

Future improvements

There are still a handful of testing utilities that are exported from contracts-* packages. We should try and refactor the packages such that this no longer is the case. This should be done in a follow-up PR.

Testing instructions

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@buildsize
Copy link

buildsize bot commented Nov 11, 2019

File name Previous Size New Size Change
init.py 26.91 KB 26.91 KB 0 bytes (0%)
abi_gen_dummy.ts 184.89 KB [deleted]
lib_dummy.ts 5.23 KB [deleted]
test_lib_dummy.ts 14.8 KB [deleted]
environment.pickle 1.61 MB 1.61 MB 0 bytes (0%)
index.doctree 194.53 KB 194.53 KB 0 bytes (0%)
.buildinfo 230 bytes 230 bytes 0 bytes (0%)
genindex.html 5.6 KB 5.6 KB 0 bytes (0%)
index.html 2.52 KB 2.52 KB 0 bytes (0%)
objects.inv 375 bytes 375 bytes 0 bytes (0%)
py-modindex.html 3.07 KB 3.07 KB 0 bytes (0%)
search.html 2.84 KB 2.84 KB 0 bytes (0%)
searchindex.js 6.3 KB 6.3 KB 0 bytes (0%)
index.rst.txt 415 bytes 415 bytes 0 bytes (0%)
alabaster.css 10.92 KB 10.92 KB 0 bytes (0%)
basic.css 11.89 KB 11.89 KB 0 bytes (0%)
custom.css 42 bytes 42 bytes 0 bytes (0%)
doctools.js 9.05 KB 9.05 KB 0 bytes (0%)
documentation_options.js 303 bytes 303 bytes 0 bytes (0%)
file.png 286 bytes 286 bytes 0 bytes (0%)
jquery-[version].js 273.79 KB 273.79 KB 0 bytes (0%)
jquery.js 86.08 KB 86.08 KB 0 bytes (0%)
language_data.js 10.59 KB 10.59 KB 0 bytes (0%)
minus.png 90 bytes 90 bytes 0 bytes (0%)
plus.png 90 bytes 90 bytes 0 bytes (0%)
pygments.css 4.69 KB 4.69 KB 0 bytes (0%)
searchtools.js 15.61 KB 15.61 KB 0 bytes (0%)
underscore-[version].js 34.34 KB 34.34 KB 0 bytes (0%)
underscore.js 11.86 KB 11.86 KB 0 bytes (0%)
contract_addresses.html 16.8 KB 16.8 KB 0 bytes (0%)
contract_artifacts.html 8.24 KB 8.24 KB 0 bytes (0%)
json_schemas.html 12.55 KB 12.55 KB 0 bytes (0%)
order_utils.html 46.85 KB 46.85 KB 0 bytes (0%)
erc20_token.html 93.31 KB 93.31 KB 0 bytes (0%)
exchange.html 678.51 KB 678.51 KB 0 bytes (0%)
tx_params.html 9.41 KB 9.41 KB 0 bytes (0%)
local_message_signer.html 15.07 KB 15.07 KB 0 bytes (0%)
asset_data_utils.html 22.65 KB 22.65 KB 0 bytes (0%)
default_api.html 118.19 KB 118.19 KB 0 bytes (0%)
asset_proxy_owner.html 350.44 KB 350.44 KB 0 bytes (0%)
coordinator.html 133.77 KB 133.77 KB 0 bytes (0%)
coordinator_registry.html 39.72 KB 39.72 KB 0 bytes (0%)
dutch_auction.html 59.6 KB 59.6 KB 0 bytes (0%)
erc20_proxy.html 111 KB 111 KB 0 bytes (0%)
erc721_proxy.html 111.12 KB 111.12 KB 0 bytes (0%)
erc721_token.html 148.29 KB 148.29 KB 0 bytes (0%)
forwarder.html 110.46 KB 110.46 KB 0 bytes (0%)
i_asset_proxy.html 39.32 KB 39.32 KB 0 bytes (0%)
i_validator.html 30.37 KB 30.37 KB 0 bytes (0%)
i_wallet.html 27.63 KB 27.63 KB 0 bytes (0%)
multi_asset_proxy.html 148.59 KB 148.59 KB 0 bytes (0%)
order_validator.html 120.52 KB 120.52 KB 0 bytes (0%)
weth9.html 133.98 KB 133.98 KB 0 bytes (0%)
zrx_token.html 111.93 KB 111.93 KB 0 bytes (0%)
dev_utils.html 580.48 KB 580.48 KB 0 bytes (0%)
types.html 8.68 KB 8.68 KB 0 bytes (0%)
erc1155_mintable.html 288.23 KB 288.23 KB 0 bytes (0%)
erc1155_proxy.html 129.7 KB 129.7 KB 0 bytes (0%)
static_call_proxy.html 39.44 KB 39.44 KB 0 bytes (0%)

@fabioberger fabioberger force-pushed the refactor/reduceContractPkgBundle branch from dd1cae3 to 30d5440 Compare November 12, 2019 10:14
@fabioberger fabioberger force-pushed the refactor/reduceContractPkgBundle branch from 628c104 to efe8225 Compare November 12, 2019 10:52
@fabioberger fabioberger marked this pull request as ready for review November 12, 2019 12:00
@coveralls
Copy link

coveralls commented Nov 12, 2019

Coverage Status

Coverage remained the same at 75.286% when pulling 03b7314 on refactor/reduceContractPkgBundle into 35099d9 on development.

Copy link
Contributor

@dorothy-zbornak dorothy-zbornak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thanks! 💯
We should definitely do more cleanup on our end, like moving balance stores out of exchange and into test-utils, etc.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants