Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory footprint #711

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
Loading