Agoric / agoric-sdk

monorepo for the Agoric Javascript smart contract platform
Apache License 2.0
327 stars 207 forks source link

add stripPrefix to @agoric/internal, use in liveslots #9996

Open warner opened 2 months ago

warner commented 2 months ago

The dbKeyToEncodedKey() function in liveslots collectionManager.js is really just stripPrefix(). That seems like a useful function to add to @agoric/internal, and then use from liveslots.

My one concern is whether it would grow the xsnap-supervisor bundle significantly (i.e. what else will get dragged in when we add @agoric/internal). Here's a recipe to find out what went into the supervisor bundle, so we can compare if/when we do that.

$ cd packages/swingset-xsnap-supervisor
$ yarn build
$ cat supervisor.bundle|jq -r .source |grep -e '\(node_modules\|packages/\)' |cut -d: -f1

That will emit a list of the packages included in the supervisor bundle (which is how liveslots gets delivered to a worker). That currently (once PR #9961 lands) includes:

At a quick glance, adding @agoric/internal might grow that with @endo/{init,stream}, @agoric/base-zone, anylogger, and jessie.js.

_Originally posted by @warner in https://github.com/Agoric/agoric-sdk/pull/9961#discussion_r1736956308_

warner commented 1 month ago

@gibson042 points out that it would be great to have CI measure the size of bundles and the reach of their dependency graph, so we could learn if/when new dependencies cause bundles to grow. Like a job that says "bundle size has grown by more than N bytes", or "bundle is now larger than N bytes", kind of like how code-coverage metric changes are reported.

We may get some better tree-shaking/etc behavior out of our Endo bundler, which may help. Currently we think it's module-at-a-time, but "barrel" modules (like a single index.js which re-exports everything of a package) tend to pull in a lot of things that aren't actually used by their clients. But we've agreed to support deep imports for @agoric/internal to reduce this problem.