rails / execjs

Run JavaScript code from Ruby
MIT License
540 stars 282 forks source link

Avoiding memory bloat with non-external runtimes #60

Open SamSaffron opened 7 years ago

SamSaffron commented 7 years ago

I have observed that when using miniracer with our precompile assets process memory can run away big time.

This is cause sprockets often bloats the heap and at the point execjs is called there are extra v8 contexts sitting around in a bloated heap that just is too big to run a GC cause so much is free in it.

Trouble is a v8 context can easily consume 100+MB of RSS.

I was wondering if we could add to execjs a concept of "OK, I am done with the context"

Once that is called, MiniRacer could release the v8 context and reclaim all the memory. This means that usage wise if you want to reclaim memory early you would do:

context = ExecJS.compile(source)
context.call("CoffeeScript.compile", "square = (x) -> x * x", bare: true)
context.release
context.call("X") => raises error cause context is done and poison at this point. 

Clearly implementation would be optional.

Thoughts ?

rafaelfranca commented 7 years ago

👍 for the idea.