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

Fix memory leak #43

Merged
merged 2 commits into from
Sep 27, 2020
Merged

Fix memory leak #43

merged 2 commits into from
Sep 27, 2020

Conversation

jonmmease
Copy link
Collaborator

@jonmmease jonmmease commented Sep 19, 2020

closes #42

It appears that repeated calls to devtools_client_->GetRuntime()->CallFunctionOn result in a slow memory leak. I wasn't able to track down the cause, and it may be chromium itself (see puppeteer/puppeteer#5893 for example).

This PR works around the issue by tracking the current JavaScript heap usage after each image export operation. When the usage exceeds 50% of the heap limit, then the page is reloaded, which does seem to effectively clear memory usage. There is a performance hit of a couple hundred milliseconds to perform this refresh, which is why I didn't do it for each export operation.

For reference, using the large figures from #42, this page reloading happens every ~20 export operations. For smaller figures, it will be much less frequent.

cc @36000

This works around an apparent memory leak by checking heap usage after each
export operation. If usage exceeds 50% of the limit, then the page is refreshed and 
the scripts are reloaded.
@jonmmease
Copy link
Collaborator Author

@36000, I uploaded wheels for this branch as release artifacts at https://github.com/plotly/Kaleido/releases/tag/v0.1.0rc1. Could you give this a try? You'll need to manually pick the right wheel for your operating system.

Assuming linux-64, you would install the wheel with

pip install https://github.com/plotly/Kaleido/releases/download/v0.1.0rc1/kaleido-0.0.3.post1.dev2+g7323d1c-py2.py3-none-manylinux1_x86_64.whl

Thanks!

@36000
Copy link

36000 commented Sep 21, 2020

This works. Thank you!

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.

Kaleido hangs on repeated write_image calls.
2 participants