Skip to content

Commit

Permalink
feat(xsnap): refined metering: stack, arrays
Browse files Browse the repository at this point in the history
 - bump METER_TYPE
 - test exact values for consensus meters (compute, allocate)
 - parser buffer size test needs higher compute limit
  • Loading branch information
dckc committed May 17, 2021
1 parent 501c1f2 commit 9c48919
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/xsnap/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/** The version identifier for our meter type.
* TODO Bump this whenever there's a change to metering semantics.
*/
export const METER_TYPE = 'xs-meter-6';
export const METER_TYPE = 'xs-meter-7';

export const ExitCode = {
E_UNKNOWN_ERROR: -1,
Expand Down
17 changes: 14 additions & 3 deletions packages/xsnap/test/test-xs-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function options() {
return { ...xsnapOptions, handleCommand, messages };
}

const { entries, fromEntries } = Object;

const shape = obj => fromEntries(entries(obj).map(([p, v]) => [p, typeof v]));

test('meter details', async t => {
const opts = options();
const vat = xsnap(opts);
Expand All @@ -42,9 +46,16 @@ test('meter details', async t => {
const {
meterUsage: { meterType, ...meters },
} = result;

t.like(
meters,
{ compute: 1_260_073, allocate: 42_074_144 },
'compute, allocate meters should be stable; update METER_TYPE?',
);

t.log(meters);
const { entries, fromEntries } = Object;
t.deepEqual(
shape(meters),
{
compute: 'number',
allocate: 'number',
Expand All @@ -55,9 +66,9 @@ test('meter details', async t => {
mapSetRemoveCount: 'number',
maxBucketSize: 'number',
},
fromEntries(entries(meters).map(([p, v]) => [p, typeof v])),
'auxiliary (non-consensus) meters are available',
);
t.is(meterType, 'xs-meter-6');
t.is(meterType, 'xs-meter-7');
});

test('high resolution timer', async t => {
Expand Down
4 changes: 2 additions & 2 deletions packages/xsnap/test/test-xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ test('property name space exhaustion: orderly fail-stop', async t => {
]) {
test(`parser buffer size ${parserBufferSize ||
'default'}k; rep ${qty}; debug ${debug}`, async t => {
const opts = options();
const vat = xsnap({ ...opts, debug, parserBufferSize });
const opts = { ...options(), meteringLimit: 1e8, debug };
const vat = xsnap({ ...opts, parserBufferSize });
t.teardown(() => vat.terminate());
const expected = failure ? [failure] : [qty * 4 + 2];
// eslint-disable-next-line no-await-in-loop
Expand Down

0 comments on commit 9c48919

Please sign in to comment.