Skip to content

Commit

Permalink
chore(xsnap): improve currentHeapCount in metering results (#10015)
Browse files Browse the repository at this point in the history
We landed the xsnap-native changes to add this field three years ago, but while cleaning up old branches, I found a test that should go along with it. Also an update to the types, and code to supply a null value if the delivery did not include any metering in the response.

refs #3910

and
#3910 (comment) in particular
  • Loading branch information
mergify[bot] committed Sep 4, 2024
2 parents c1156cd + c014d2e commit ebdf706
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/xsnap/src/xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export async function xsnap(options) {
* @template T
* @typedef {object} RunResult
* @property {T} reply
* @property {{ meterType: string, allocate: number|null, compute: number|null, timestamps: number[]|null }} meterUsage
* @property {{ meterType: string, allocate: number|null, compute: number|null, currentHeapCount: number|null, timestamps: number[]|null }} meterUsage
*/

/**
Expand All @@ -312,7 +312,12 @@ export async function xsnap(options) {
xsnapProcess.kill();
throw Error('xsnap protocol error: received empty message');
} else if (message[0] === OK) {
let meterInfo = { compute: null, allocate: null, timestamps: [] };
let meterInfo = {
compute: null,
allocate: null,
currentHeapCount: null,
timestamps: [],
};
const meterSeparator = message.indexOf(OK_SEPARATOR, 1);
if (meterSeparator >= 0) {
// The message is `.meterdata\1reply`.
Expand Down
2 changes: 1 addition & 1 deletion packages/xsnap/test/xs-perf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('meter details', async t => {

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

Expand Down

0 comments on commit ebdf706

Please sign in to comment.