Skip to content

Commit 82e2209

Browse files
committed
fix(xsnap)!: upgrade to latest XS
* fix a major memory leak: 64 bytes per Map `delete()`, 32 per Set `delete()` * should: closes #3839 * unfortunately Map/Set deletion is now O(N) not O(1) * possibly fix #3877 "cannot read (corrupted?) snapshot" Note that this breaks snapshot compatibility, and probably metering compatibility. closes #3889
1 parent bdc626b commit 82e2209

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

packages/SwingSet/test/test-xsnap-store.js

+32-12
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const relativeSize = (fn, fullSize) =>
3535
const snapSize = {
3636
raw: 417,
3737
SESboot: 858,
38-
compression: 0.1,
3938
};
4039

4140
/**
@@ -69,7 +68,7 @@ async function bootSESWorker(name, handleCommand) {
6968
return bootWorker(name, handleCommand, bootScript);
7069
}
7170

72-
test(`create XS Machine, snapshot (${snapSize.raw} Kb), compress to ${snapSize.compression}x`, async t => {
71+
test(`create XS Machine, snapshot (${snapSize.raw} Kb), compress to smaller`, async t => {
7372
const vat = await bootWorker('xs1', async m => m, '1 + 1');
7473
t.teardown(() => vat.close());
7574

@@ -84,9 +83,8 @@ test(`create XS Machine, snapshot (${snapSize.raw} Kb), compress to ${snapSize.c
8483
});
8584

8685
const zfile = path.resolve(pool.name, `${h}.gz`);
87-
t.is(
88-
relativeSize(zfile, snapSize.raw),
89-
snapSize.compression,
86+
t.true(
87+
relativeSize(zfile, snapSize.raw) < 0.5,
9088
'compressed snapshots are smaller',
9189
);
9290
});
@@ -107,9 +105,8 @@ test('SES bootstrap, save, compress', async t => {
107105
});
108106

109107
const zfile = path.resolve(pool.name, `${h}.gz`);
110-
t.is(
111-
relativeSize(zfile, snapSize.SESboot),
112-
0.2,
108+
t.true(
109+
relativeSize(zfile, snapSize.SESboot) < 0.5,
113110
'compressed snapshots are smaller',
114111
);
115112
});
@@ -141,7 +138,7 @@ test('create SES worker, save, restore, resume', async t => {
141138
* that is: any changes to the SES shim or to the
142139
* xsnap-worker supervisor.
143140
*/
144-
test('XS + SES snapshots are deterministic', async t => {
141+
test('XS + SES snapshots are long-term deterministic', async t => {
145142
const pool = tmp.dirSync({ unsafeCleanup: true });
146143
t.teardown(() => pool.removeCallback());
147144
t.log({ pool: pool.name });
@@ -155,7 +152,7 @@ test('XS + SES snapshots are deterministic', async t => {
155152

156153
t.is(
157154
h1,
158-
'817ce29f1f0f460a0066ec257b9941803b3f9fea4ad87a8a7a76f458d9f8a65b',
155+
'9b90f329ae31e65bfb9b3f8436ceb581e160b3ec9984e9ac1dcef23ae78338fb',
159156
'initial snapshot',
160157
);
161158

@@ -167,15 +164,38 @@ test('XS + SES snapshots are deterministic', async t => {
167164
const h2 = await store.save(vat.snapshot);
168165
t.is(
169166
h2,
170-
'f62c6fce5accbbfbb5f08bb25f9414e9ba611359af1fb3a889d6171e25e58d6a',
167+
'b3bd291a9b42abb6acbe488a4da0c0eacee417a9f0ca94b88f7fbe4191bc43a0',
171168
'after SES boot',
172169
);
173170

174171
await vat.evaluate('globalThis.x = harden({a: 1})');
175172
const h3 = await store.save(vat.snapshot);
176173
t.is(
177174
h3,
178-
'911f4ea5fa42b5245d7024f269c59bdf382dc0521146ecc03e017136023f9435',
175+
'834f6333c6c51aec41cb9aa8e8665c04a868c7c57ff0a356a0b72d82eeca578b',
179176
'after use of harden()',
180177
);
181178
});
179+
180+
async function makeTestSnapshot(t) {
181+
const pool = tmp.dirSync({ unsafeCleanup: true });
182+
t.teardown(() => pool.removeCallback());
183+
// t.log({ pool: pool.name });
184+
await fs.promises.mkdir(pool.name, { recursive: true });
185+
const store = makeSnapStore(pool.name, makeSnapStoreIO());
186+
const vat = await bootWorker('xs1', async m => m, '1 + 1');
187+
const bootScript = await ld.asset(
188+
'@agoric/xsnap/dist/bundle-ses-boot.umd.js',
189+
);
190+
await vat.evaluate(bootScript);
191+
await vat.evaluate('globalThis.x = harden({a: 1})');
192+
const hash = await store.save(vat.snapshot);
193+
await vat.close();
194+
return hash;
195+
}
196+
197+
test('XS + SES snapshots are short-term deterministic', async t => {
198+
const h1 = await makeTestSnapshot(t);
199+
const h2 = await makeTestSnapshot(t);
200+
t.is(h1, h2);
201+
});

packages/xsnap/moddable

Submodule moddable updated 73 files

0 commit comments

Comments
 (0)