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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory heap usage increases when importing mathjs #8832

Closed
sublayerio opened this issue Aug 15, 2019 · 8 comments
Closed

Memory heap usage increases when importing mathjs #8832

sublayerio opened this issue Aug 15, 2019 · 8 comments

Comments

@sublayerio
Copy link

sublayerio commented Aug 15, 2019

馃悰 Bug Report

Memory heap continues to grow when importing mathjs library.

To Reproduce

Steps to reproduce the behavior:

Create several test files that import the mathjs library.

Screenshot 2019-08-15 at 19 49 40

Screenshot 2019-08-15 at 19 46 02

Screenshot 2019-08-15 at 19 46 16

Expected behavior

Memory heap usage should not increase or at least not as much.

Link to repl or repo (highly encouraged)

Checkout this repo.

https://github.com/keyflight/memory-mathjs-jest

Install the dependencies.

yarn install

Run the following commands to compare

yarn tests-without-mathjs
yarn tests-with-mathjs

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 10.15.3 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0 
@SimenB
Copy link
Member

SimenB commented Aug 15, 2019

Hmm, this is odd. Does mathjs keep references to any globals? Or override any node core modules (we had an issue about a leak with somebody overriding something on http without cleaning up, but I'm unable to find the issue). E.g. const keepMath = global.Math or some such? Quick look at the module showed it was minified, so not the easiest to debug without messing in node_modules

@Mark1626
Copy link
Contributor

Mark1626 commented Aug 26, 2019

Hope this might me useful for anyone who is looking into this. I ran the tests with a custom environment, jest-circus(to use handleTestEvent) and took snapshots with heapdump before the test_start event.

This is the snapshot from the 10th test run, it looks that _moduleRegistry in Runtime seems to be retained. I'll dig into the code to see if I can find anything

heapdump

@SimenB A second opinion might be good.

@Mark1626
Copy link
Contributor

@SimenB resetModules is by default false as per the documentation

https://jestjs.io/docs/en/configuration#resetmodules-boolean

The memory leak caused by #8282 is only fixed when resetModules is true

https://github.com/facebook/jest/blob/fb7b132b7230dac3fca30d79fcc57c98ecffbc81/packages/jest-runtime/src/index.ts#L539-L543

@SimenB
Copy link
Member

SimenB commented Aug 26, 2019

@scotthovestadt ^

@terite
Copy link
Contributor

terite commented Feb 4, 2020

I was able to reproduce this with mathjs 6.6.0 and jest 25.1.0 when running with the following command

jest --detectLeaks --runInBand --no-cache --logHeapUsage

With the following command, jest detects no leaks

node --expose-gc ./node_modules/.bin/jest --detectLeaks --runInBand --no-cache --logHeapUsage

Here is the repository I used for testing - https://github.com/terite/jest-unleak-modules

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 3, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants