Avoiding memory bloat with non-external runtimes

Open
#60 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
ruby
Domain
tooling

Research direction

Start with the ExecJS.compile and compiled-context call API described in the issue, then trace how non-external runtimes manage their contexts. Define the release lifecycle and behavior after release, including whether memory is reclaimed by MiniRacer. The issue does not name implementation files or tests, so those must be located before work can be scoped.

Written by the indexing model from the issue text.

Description

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 ?

Dominant language
Ruby
Stars
578
Forks
286
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rails/execjs

All issues in rails/execjs

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.