Skip to content

Commit

Permalink
Reduce memory footprint
Browse files Browse the repository at this point in the history
  • Loading branch information
appurva21 committed Aug 29, 2024
1 parent 5000577 commit 31ebb0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lib/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
};
Expand All @@ -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 */
Expand Down
1 change: 0 additions & 1 deletion lib/worker.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions test/benchmark/memory-footprint.test.js
Original file line number Diff line number Diff line change
@@ -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 () {

Check warning on line 6 in test/benchmark/memory-footprint.test.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected skipped mocha test
it('should not increase memory footprint significantly', function (done) {
done();
});
});

0 comments on commit 31ebb0e

Please sign in to comment.