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

Conversation

appurva21
Copy link
Member

Context / Issue:

bridge.js receives the options object as an argument with bootCode supplied by the consumer.

Inside bridge.js, worker is spawned and multiple event/timers are setup. bootCode string is only required to spawn the worker and should get garbage collected post that. But right now, while adding event listeners and callbacks for timers, options object is referenced, which prevents GC of options.bootCode.

Fix:

Destructure options and directly use the values wherever required to prevent unintended references to the complete object.

Benchmark:

script:

const UniversalVM = require('uvm');

UniversalVM.spawn({
    bootCode: `
        bridge.on('loopback', function (data) {
            bridge.dispatch('loopback', data);
        });
       /* INSERT 10MB string here */
    `
}, (_, context) => {
    context.on('loopback', function () {
       context.disconnect();
    });

    context.dispatch('loopback');
});

Baseline (develop, empty bootCode): 3.8MB

image

Before Fix (develop, 10.5MB bootCode): 24.7MB (3.8 + ~2*10.5)

Note

  • options.bootCode persisted (second string in the right panel)
  • the script has significant memory footprint as well due to the presence of large string in it, thus 2*10.5
    image

After fix (current, 10.5MB bootCode): 14.2MB (3.8 + 10.5)

image

@appurva21 appurva21 force-pushed the feature/reduce-memory-footprint branch from dc0abcd to 46a2e9c Compare August 29, 2024 04:37
@appurva21 appurva21 force-pushed the feature/refactor-worker-interface branch from f5671df to 0bafbe5 Compare August 29, 2024 04:38
Copy link

codecov bot commented Aug 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (cc7fda1) to head (a042d2d).
Report is 1 commits behind head on feature/refactor-worker-interface.

Additional details and impacted files
@@                         Coverage Diff                         @@
##           feature/refactor-worker-interface      #711   +/-   ##
===================================================================
  Coverage                             100.00%   100.00%           
===================================================================
  Files                                      5         5           
  Lines                                    108       109    +1     
  Branches                                  10        10           
===================================================================
+ Hits                                     108       109    +1     
Flag Coverage Δ
unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@appurva21 appurva21 force-pushed the feature/reduce-memory-footprint branch from 46a2e9c to 31ebb0e Compare August 29, 2024 04:40
@appurva21 appurva21 force-pushed the feature/reduce-memory-footprint branch from 31ebb0e to a042d2d Compare September 23, 2024 05:02
@codenirvana codenirvana merged commit e28b223 into feature/refactor-worker-interface Sep 24, 2024
10 checks passed
@codenirvana codenirvana deleted the feature/reduce-memory-footprint branch September 24, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants