@agoric/swingset-vat 0.32.3-dev-5ec590e.0.5ec590e → 0.32.3-dev-d1bb9cd.0.d1bb9cd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/swingset-vat",
3
- "version": "0.32.3-dev-5ec590e.0.5ec590e",
3
+ "version": "0.32.3-dev-d1bb9cd.0.d1bb9cd",
4
4
  "description": "Vat/Container Launcher",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -22,7 +22,7 @@
22
22
  "lint:eslint": "node ../../scripts/eslint-repo.mjs ."
23
23
  },
24
24
  "devDependencies": {
25
- "@agoric/xsnap": "0.14.3-dev-5ec590e.0.5ec590e",
25
+ "@agoric/xsnap": "0.14.3-dev-d1bb9cd.0.d1bb9cd",
26
26
  "@types/better-sqlite3": "^7.6.13",
27
27
  "@types/microtime": "^2.1.0",
28
28
  "@types/tmp": "^0.2.0",
@@ -30,15 +30,15 @@
30
30
  "ava": "^6.4.1"
31
31
  },
32
32
  "dependencies": {
33
- "@agoric/internal": "0.3.3-dev-5ec590e.0.5ec590e",
34
- "@agoric/kmarshal": "0.1.1-dev-5ec590e.0.5ec590e",
35
- "@agoric/store": "0.9.3-dev-5ec590e.0.5ec590e",
36
- "@agoric/swing-store": "0.9.2-dev-5ec590e.0.5ec590e",
37
- "@agoric/swingset-liveslots": "0.10.3-dev-5ec590e.0.5ec590e",
38
- "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-5ec590e.0.5ec590e",
39
- "@agoric/time": "0.3.3-dev-5ec590e.0.5ec590e",
40
- "@agoric/vat-data": "0.5.3-dev-5ec590e.0.5ec590e",
41
- "@agoric/xsnap-lockdown": "0.14.1-dev-5ec590e.0.5ec590e",
33
+ "@agoric/internal": "0.3.3-dev-d1bb9cd.0.d1bb9cd",
34
+ "@agoric/kmarshal": "0.1.1-dev-d1bb9cd.0.d1bb9cd",
35
+ "@agoric/store": "0.9.3-dev-d1bb9cd.0.d1bb9cd",
36
+ "@agoric/swing-store": "0.9.2-dev-d1bb9cd.0.d1bb9cd",
37
+ "@agoric/swingset-liveslots": "0.10.3-dev-d1bb9cd.0.d1bb9cd",
38
+ "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-d1bb9cd.0.d1bb9cd",
39
+ "@agoric/time": "0.3.3-dev-d1bb9cd.0.d1bb9cd",
40
+ "@agoric/vat-data": "0.5.3-dev-d1bb9cd.0.d1bb9cd",
41
+ "@agoric/xsnap-lockdown": "0.14.1-dev-d1bb9cd.0.d1bb9cd",
42
42
  "@endo/base64": "^1.0.12",
43
43
  "@endo/bundle-source": "^4.1.2",
44
44
  "@endo/captp": "^4.4.8",
@@ -113,5 +113,5 @@
113
113
  "typeCoverage": {
114
114
  "atLeast": 76.72
115
115
  },
116
- "gitHead": "5ec590e7aa787c5d8fb778a7cf14ec68f252fb83"
116
+ "gitHead": "d1bb9cd8ec3f764f64cda4b331c66e37ad179a73"
117
117
  }
@@ -177,6 +177,15 @@ export async function makeSwingsetController(
177
177
  ),
178
178
  } = runtimeOptions;
179
179
 
180
+ const shouldProfileStartup = env.SWINGSET_STARTUP_PROFILE === '1';
181
+ /** @type {Array<{ label: string, ms: number }>} */
182
+ const startupPhases = [];
183
+ const noteStartupPhase = (label, ms) => {
184
+ if (shouldProfileStartup) {
185
+ startupPhases.push({ label, ms });
186
+ }
187
+ };
188
+
180
189
  if (typeof Compartment === 'undefined') {
181
190
  throw Error('SES must be installed before calling makeSwingsetController');
182
191
  }
@@ -307,7 +316,17 @@ export async function makeSwingsetController(
307
316
  const kernelBundle = await slogDuration(
308
317
  ['bundle-kernel-start', 'bundle-kernel-finish'],
309
318
  {},
310
- async () => runtimeOptions.kernelBundle ?? buildKernelBundle(),
319
+ async () => {
320
+ await null;
321
+ const t0 = performance.now();
322
+ const resolved =
323
+ (await runtimeOptions.kernelBundle) ?? (await buildKernelBundle());
324
+ noteStartupPhase(
325
+ 'controller.buildKernelBundle',
326
+ performance.now() - t0,
327
+ );
328
+ return resolved;
329
+ },
311
330
  );
312
331
 
313
332
  // FIXME: Put this somewhere better.
@@ -327,6 +346,7 @@ export async function makeSwingsetController(
327
346
  ['import-kernel-start', 'import-kernel-finish'],
328
347
  {},
329
348
  async () => {
349
+ const t0 = performance.now();
330
350
  const kernelNS = await importBundle(kernelBundle, {
331
351
  filePrefix: 'kernel/...',
332
352
  endowments: {
@@ -341,12 +361,17 @@ export async function makeSwingsetController(
341
361
  Base64: globalThis.Base64, // Available only on XSnap
342
362
  },
343
363
  });
364
+ noteStartupPhase(
365
+ 'controller.importKernelBundle',
366
+ performance.now() - t0,
367
+ );
344
368
  return /** @type {typeof kernelDefault} */ (kernelNS.default);
345
369
  },
346
370
  );
347
371
 
348
372
  const kernelEndowments = {
349
373
  waitUntilQuiescent,
374
+ now: () => performance.now(),
350
375
  kernelStorage,
351
376
  debugPrefix,
352
377
  // all vats get these in their global scope, plus a vat-specific 'console'
@@ -366,6 +391,7 @@ export async function makeSwingsetController(
366
391
  verbose,
367
392
  warehousePolicy,
368
393
  overrideVatManagerOptions,
394
+ startupProfiler: noteStartupPhase,
369
395
  };
370
396
 
371
397
  const kernel = buildKernel(
@@ -374,7 +400,11 @@ export async function makeSwingsetController(
374
400
  kernelRuntimeOptions,
375
401
  );
376
402
 
377
- await kernel.start();
403
+ {
404
+ const t0 = performance.now();
405
+ await kernel.start();
406
+ noteStartupPhase('controller.kernel.start', performance.now() - t0);
407
+ }
378
408
 
379
409
  /**
380
410
  * Validate and install a code bundle.
@@ -615,6 +645,14 @@ export async function makeSwingsetController(
615
645
  },
616
646
  });
617
647
  });
648
+ if (shouldProfileStartup) {
649
+ const rows = startupPhases
650
+ .sort((a, b) => b.ms - a.ms)
651
+ .map(({ label, ms }) => `${label}=${ms.toFixed(1)}ms`)
652
+ .join(', ');
653
+ // Use ambient console so profiling output is visible regardless of logger levels.
654
+ console.error(`startup-profile: ${rows}`);
655
+ }
618
656
 
619
657
  return controller;
620
658
  }
@@ -160,6 +160,7 @@ export default function buildKernel(
160
160
  ) {
161
161
  const {
162
162
  waitUntilQuiescent,
163
+ now = () => 0,
163
164
  kernelStorage,
164
165
  debugPrefix,
165
166
  vatEndowments,
@@ -179,7 +180,11 @@ export default function buildKernel(
179
180
  verbose,
180
181
  warehousePolicy,
181
182
  overrideVatManagerOptions = {},
183
+ startupProfiler = undefined,
182
184
  } = kernelRuntimeOptions;
185
+ const noteStartupPhase = (label, ms) => {
186
+ startupProfiler && startupProfiler(label, ms);
187
+ };
183
188
  const logStartup = verbose ? console.debug : () => {};
184
189
  if (verbose) kdebugEnable(true);
185
190
 
@@ -1844,7 +1849,11 @@ export default function buildKernel(
1844
1849
 
1845
1850
  kernelKeeper.loadStats();
1846
1851
 
1847
- await vatWarehouse.start(logStartup);
1852
+ {
1853
+ const t0 = now();
1854
+ await vatWarehouse.start(logStartup);
1855
+ noteStartupPhase('kernel.vatWarehouse.start', now() - t0);
1856
+ }
1848
1857
 
1849
1858
  // the admin device is endowed directly by the kernel
1850
1859
  deviceEndowments.vatAdmin = {
@@ -1863,6 +1872,7 @@ export default function buildKernel(
1863
1872
  // instantiate all devices
1864
1873
  for (const [name, deviceID] of kernelKeeper.getDevices()) {
1865
1874
  logStartup(`starting device ${name} as ${deviceID}`);
1875
+ const deviceStart = now();
1866
1876
  const deviceKeeper = kernelKeeper.allocateDeviceKeeperIfNeeded(deviceID);
1867
1877
  const { source, options } = deviceKeeper.getSourceAndOptions();
1868
1878
  assert(source.bundleID);
@@ -1870,6 +1880,7 @@ export default function buildKernel(
1870
1880
  const { deviceParameters = {}, unendowed } = options;
1871
1881
  const devConsole = makeConsole(`${debugPrefix}SwingSet:dev-${name}`);
1872
1882
 
1883
+ const bundleLoadStart = now();
1873
1884
  const bundle = kernelKeeper.getBundle(source.bundleID);
1874
1885
  assert(bundle);
1875
1886
  const NS = await importBundle(bundle, {
@@ -1881,6 +1892,10 @@ export default function buildKernel(
1881
1892
  assert: globalThis.assert,
1882
1893
  }),
1883
1894
  });
1895
+ noteStartupPhase(
1896
+ `kernel.device.${name}.importBundle`,
1897
+ now() - bundleLoadStart,
1898
+ );
1884
1899
 
1885
1900
  if (deviceEndowments[name] || unendowed) {
1886
1901
  const translators = makeDeviceTranslators(deviceID, name, kernelKeeper);
@@ -1921,6 +1936,7 @@ export default function buildKernel(
1921
1936
  `WARNING: skipping device ${deviceID} (${name}) because it has no endowments`,
1922
1937
  );
1923
1938
  }
1939
+ noteStartupPhase(`kernel.device.${name}.total`, now() - deviceStart);
1924
1940
  }
1925
1941
 
1926
1942
  // attach vat-admin device hooks
@@ -266,8 +266,11 @@ export function makeVatWarehouse({
266
266
  panic,
267
267
  warehousePolicy,
268
268
  }) {
269
- const { maxVatsOnline = 50, restartWorkerOnSnapshot = true } =
270
- warehousePolicy || {};
269
+ const {
270
+ maxVatsOnline = 50,
271
+ maxPreloadVats = maxVatsOnline / 2,
272
+ restartWorkerOnSnapshot = true,
273
+ } = warehousePolicy || {};
271
274
  // Often a large contract evaluation is among the first few deliveries,
272
275
  // so let's do a snapshot after just a few deliveries.
273
276
  const snapshotInitial = kernelKeeper.getSnapshotInitial();
@@ -430,7 +433,7 @@ export function makeVatWarehouse({
430
433
  /** @param {typeof console.log} logStartup */
431
434
  async function start(logStartup) {
432
435
  const recreate = true; // note: PANIC on failure to recreate
433
- const maxPreload = maxVatsOnline / 2;
436
+ const maxPreload = maxPreloadVats;
434
437
  let numPreloaded = 0;
435
438
 
436
439
  // NOTE: OPTIMIZATION OPPORTUNITY: replay vats in parallel
@@ -320,6 +320,7 @@ export {};
320
320
  /**
321
321
  * @typedef {object} VatWarehousePolicy
322
322
  * @property { number } [maxVatsOnline] Limit the number of simultaneous workers
323
+ * @property { number } [maxPreloadVats] Limit the number of vats preloaded at startup
323
324
  * @property { boolean } [restartWorkerOnSnapshot] Reload worker immediately upon snapshot creation
324
325
  */
325
326
 
@@ -107,7 +107,9 @@ harden(defaultBundleToolEventSink);
107
107
  const inferLogPhase = args => {
108
108
  const joined = args.map(arg => String(arg)).join(' ');
109
109
  let phase = '[check]';
110
- if (joined.includes(' add:') || joined.includes(' bundled ')) {
110
+ if (joined.includes(' add:')) {
111
+ phase = '[queue]';
112
+ } else if (joined.includes(' bundled ')) {
111
113
  phase = '[rebuilt]';
112
114
  }
113
115
  return phase;