From e3e0acd9ebf65eed74c3f9bc15acdbbe783773ab Mon Sep 17 00:00:00 2001 From: Appurva Murawat Date: Sat, 24 Aug 2024 22:11:05 +0530 Subject: [PATCH 1/3] Refactor bridge and workers to match node's interface --- lib/worker.browser.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/worker.browser.js b/lib/worker.browser.js index 7b0ffc8..74eb130 100644 --- a/lib/worker.browser.js +++ b/lib/worker.browser.js @@ -82,6 +82,7 @@ class WebWorker { })(self.close) const onError = function (event) { + console.log('$$$ onError', event.constructor.name, event.type, event.name); if (bridge.listeners('uncaughtException').length) { event.preventDefault(); return bridge.emit('uncaughtException', event.error || event.reason); From 85d1024a982aff3b0810d9025de19fe5fc8f8bdf Mon Sep 17 00:00:00 2001 From: Appurva Murawat Date: Mon, 26 Aug 2024 23:25:24 +0530 Subject: [PATCH 2/3] Reduce memory footprint --- lib/bridge.js | 13 +++++++------ lib/worker.browser.js | 1 - test/benchmark/memory-footprint.test.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 test/benchmark/memory-footprint.test.js diff --git a/lib/bridge.js b/lib/bridge.js index 39655e8..de3b5ac 100644 --- a/lib/bridge.js +++ b/lib/bridge.js @@ -67,6 +67,7 @@ module.exports = function (bridge, options, callback) { firmwareCode; const id = UVM_ID_ + randomNumber(), + { bootCode, debug, bootTimeout, _sandbox } = options, // function to forward messages emitted forwardEmits = (e) => { @@ -105,7 +106,7 @@ module.exports = function (bridge, options, callback) { worker.off(EXIT, forwardExit); - (options._sandbox ? Promise.resolve() : worker.terminate()) + (_sandbox ? Promise.resolve() : worker.terminate()) .then(() => { callback(); }); worker = null; }; @@ -131,18 +132,18 @@ module.exports = function (bridge, options, callback) { }); // get firmware code string with boot code - firmwareCode = sandboxFirmware(options.bootCode, id, options.debug); + firmwareCode = sandboxFirmware(bootCode, id, debug); // start boot timer, stops once we get the load signal, terminate otherwise bootTimer = setTimeout(() => { terminateWorker(); - callback(new Error(`uvm: boot timed out after ${options.bootTimeout}ms.`)); - }, options.bootTimeout); + callback(new Error(`uvm: boot timed out after ${bootTimeout}ms.`)); + }, bootTimeout); // if sandbox worker is provided, we simply need to init with firmware code // @todo validate sandbox type or APIs - if (options._sandbox) { - worker = options._sandbox; + if (_sandbox) { + worker = _sandbox; // add event listener methods for Web worker /* istanbul ignore next-line */ diff --git a/lib/worker.browser.js b/lib/worker.browser.js index 74eb130..7b0ffc8 100644 --- a/lib/worker.browser.js +++ b/lib/worker.browser.js @@ -82,7 +82,6 @@ class WebWorker { })(self.close) const onError = function (event) { - console.log('$$$ onError', event.constructor.name, event.type, event.name); if (bridge.listeners('uncaughtException').length) { event.preventDefault(); return bridge.emit('uncaughtException', event.error || event.reason); diff --git a/test/benchmark/memory-footprint.test.js b/test/benchmark/memory-footprint.test.js new file mode 100644 index 0000000..57d8cec --- /dev/null +++ b/test/benchmark/memory-footprint.test.js @@ -0,0 +1,10 @@ + +// TODO: Implement this test +// v8.getHeapStatistics() can be used to measure memory +// footprint but the results from it are not consistent with +// values from heap snapshots created manually in Chrome DevTools. +describe.skip('memory footprint', function () { + it('should not increase memory footprint significantly', function (done) { + done(); + }); +}); From a042d2da9ed4228f56d1ad6f0d2a1ffa02cc5c8f Mon Sep 17 00:00:00 2001 From: Appurva Murawat Date: Mon, 23 Sep 2024 10:32:01 +0530 Subject: [PATCH 3/3] Add changelog --- CHANGELOG.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 041884f..959ab03 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -1,4 +1,6 @@ unreleased: + fixed bugs: + - GH-711 Fixed an issue where boot code was not being garbage collected chores: - GH-710 Refactor worker interface to be node alike