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

huge memory leak #909

Closed
pps83 opened this issue Mar 30, 2016 · 6 comments
Closed

huge memory leak #909

pps83 opened this issue Mar 30, 2016 · 6 comments
Milestone

Comments

@pps83
Copy link

pps83 commented Mar 30, 2016

It looks like js-beautify is a giant memory hog. It wasn't meant to be used in code by long-running aps?
If I take any minified js file from google and run js-beautify in a loop I get 50-100M plus on each iteration.

@bitwiseman
Copy link
Member

Are you talking about the python implementation or the javascript one? Could you provide an example of how you measured this?

@pps83
Copy link
Author

pps83 commented Mar 30, 2016

I'm talking about js version. I tested more with different scripts, looks like some perhaps trigger some weird results. For example, paste into node:

var request = require('request'), beautify = require('js-beautify').js_beautify, base_js;
function test_beautify(){
    beautify(base_js);
    setTimeout(test_beautify, 1000);
}
request('https://s.ytimg.com/yts/jsbin/player-en_US-vfl9rzyi6/base.js', function(err, req, body){
    base_js = body;
    test_beautify();
});

This will take hundreds of megs of ram in no time. With other scripts I saw less dramatic results where ram seems to stay stable (e.g. with jquery: https://code.jquery.com/jquery-1.12.2.min.js)

@bitwiseman bitwiseman added this to the v2.0.0 milestone Mar 30, 2016
@bitwiseman
Copy link
Member

I can reproduce the issue with the file you sent. Thanks!
That said, I don't have time to track it down currently. I'll keep it on the list for a future release.

@pps83
Copy link
Author

pps83 commented Mar 30, 2016

Any pointers on how I could track it down myself?

@bitwiseman
Copy link
Member

You can try turning off the formatting handlers (so only parsing runs) - comment out the line that calls the handlers formatting. Then turn the handlers back on one by one.

Chrome has a memory profiler that might help as well.

@bitwiseman
Copy link
Member

bitwiseman commented Mar 31, 2016

This seems to fix the issue: https://github.com/beautify-web/js-beautify/tree/feature/memory-leak . Minor performance degradation, but acceptable. I'll look at including it in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants