From 6dda5c4963207d308464d54e9187a317bf344a6b Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Tue, 23 Feb 2021 11:26:00 -0800 Subject: [PATCH] use performance.mark to measure deserialize time --- src/virtual-machine.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 5cec44c10..17440c736 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -478,6 +478,9 @@ class VirtualMachine extends EventEmitter { // Clear the current runtime this.clear(); + if (typeof performance !== 'undefined') { + performance.mark('scratch-vm-deserialize-start'); + } const runtime = this.runtime; const deserializePromise = function () { const projectVersion = projectJSON.projectVersion; @@ -492,8 +495,14 @@ class VirtualMachine extends EventEmitter { return Promise.reject('Unable to verify Scratch Project version.'); }; return deserializePromise() - .then(({targets, extensions}) => - this.installTargets(targets, extensions, true)); + .then(({targets, extensions}) => { + if (typeof performance !== 'undefined') { + performance.mark('scratch-vm-deserialize-end'); + performance.measure('scratch-vm-deserialize', + 'scratch-vm-deserialize-start', 'scratch-vm-deserialize-end'); + } + return this.installTargets(targets, extensions, true); + }); } /**