Skip to content

Instantly share code, notes, and snippets.

@warner
Last active November 7, 2022 04:36
Show Gist options
  • Save warner/3e5214a0a14cd5799ac9646177d32eee to your computer and use it in GitHub Desktop.
Save warner/3e5214a0a14cd5799ac9646177d32eee to your computer and use it in GitHub Desktop.
marshal benchmark data
//
// Large data for marshal benchmarking
//
// 'serialized.js' contains JSON-encoded capdata ({ body, slots })
// with a 621kB body and 643 slots. It represents the state of a
// Wallet after many trade operations had been executed (and not all
// of them were cleaned up: think of it as a worst-case serialization
// task).
import '@endo/init';
import { Far, makeMarshal } from '@endo/marshal';
import { serialized } from './serialized.js';
console.log('serialized.length:', serialized.length);
const capdata = JSON.parse(serialized);
console.log('body.length', capdata.body.length);
console.log('slots.length', capdata.slots.length);
// const shadow = JSON.parse(capdata.body);
// console.log(Object.keys(shadow));
let count = 0;
const convertValToSlot = (val) => {
count += 1;
return `unknown:${count}`;
};
const convertSlotToVal = (slot, iface) => Far(iface, {});
const m = makeMarshal(convertValToSlot, convertSlotToVal);
// This 'data' is the source data that needs to be serialized. If
// you're writing a benchmark script, the 'init' phase should perform
// this extraction, and then the 'execute' phase (whose time we
// measure) should perform the m.serialize below.
const data = m.unserialize(capdata);
console.log(Object.keys(data));
console.log(data.contacts[0]);
const cd2 = m.serialize(data);
console.log('cd2.body.length', cd2.body.length);
console.log('cd2.slots.length', cd2.slots.length);
This file has been truncated, but you can view the full file.
@erights
Copy link

erights commented Nov 7, 2022

Should this be put in a reusable place? I wonder how well it does now on the same hardware, and how well it does with smallcaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment