Skip to content

Commit

Permalink
Reduce memory footprint (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
appurva21 authored Sep 24, 2024
1 parent cc7fda1 commit e28b223
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
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
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 e28b223

Please sign in to comment.