Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amortize kernel-source bundling process during large unit tests #1643

Closed
warner opened this issue Aug 30, 2020 · 1 comment
Closed

amortize kernel-source bundling process during large unit tests #1643

warner opened this issue Aug 30, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request SwingSet package: SwingSet

Comments

@warner
Copy link
Member

warner commented Aug 30, 2020

What is the Problem Being Solved?

Swingset-using unit tests take too long to run.

Several swingset unit tests, like test-message-patterns.js, build many instances of the kernel (about 60) and run a small number of operations in each. The kernel needs several sounds bundles to do its job:

  • kernel.js (the kernel source itself)
  • the vat-admin device and its wrapper vat
  • the timer device and its wrapper vat
  • the comms vat, and the VatTP vat

To avoid a manual yarn build step (which would cause really confusing errors if you forget to run it), buildVatController() function bundles these sources into bundle objects at runtime. But the bundling process (which uses rollup) is fairly slow, depending upon the amount of code being bundled: the kernel source takes about 1.5s to bundle on my machine. When we're building a lot of swingsets in a single test file, this times adds up. test-message-patterns.js takes about 230s when run serially. By building all the bundles once and sharing them between calls to buildVatController(), this can be reduced to about 15s.

Description of the Design

buildVatController() already accepts a runtimeOptions bag, but currently only accepts debugPrefix and verbose options. I'm going to add a kernelBundles option, as well as a new exported buildKernelBundles() function. The default behavior will be for buildVatController to bundle the sources itself, but tests can call buildKernelBundles() and get back an object (clonable data) that can be passed instead.

cc @FUDCo

@warner warner added enhancement New feature or request SwingSet package: SwingSet labels Aug 30, 2020
@warner warner self-assigned this Aug 30, 2020
warner added a commit that referenced this issue Aug 30, 2020
Using `rollup` to turn a tree of vat-defining source files into a bundle
object is somewhat slow. It seems to depend on the amount of code being
bundled: the worst case is the kernel sources, which take 1.5s . The kernel
needs a number of other vats which are automatically bundled at runtime. The
total process takes about 2.7s on my machine.

We have unit tests that run many swingsets in a single test file. The most
extreme case is test-message-patterns.js, which calls `buildVatController` 60
times in a row. It takes a really long time to run, 3-6 minutes, and the
majority is the bundling step. Parallelizing this doesn't help (JS is a
single-threaded language, it's not using non-blocking filesystem operations,
I don't know whether it's CPU or IO bound but either would be a problem).

This patch exports a new `buildKernelBundles()` function to let these
multi-swingset tests build the bundles once per test file. It also adds
`kernelBundles` to the `buildVatController(.., .., runtimeOptions)` options
bag to pass these bundles back in (with sensible defaults). The controller
gets all the built-in bundles from this collection, rather than running
`bundleSource` each time.

It also rearranges the console setup slightly, to make the `console` object
available earlier within `buildVatController`. I needed this to debug
problems with unpacking the other `runtimeOptions`. Also, now that we're
building our own `console` object, we no longer need to explicitly harden the
native console's (unique) prototype object.

refs #1643
@warner
Copy link
Member Author

warner commented Jan 4, 2021

I implemented this in #1644 and enabled it for several swingset tests that build a lot of swingsets in a single test, so we've probably picked the low-hanging fruit on this one. Closing.

@warner warner closed this as completed Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SwingSet package: SwingSet
Projects
None yet
Development

No branches or pull requests

1 participant