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

Cache compiled classes between scripts #32

Closed
gbrail opened this issue Dec 18, 2013 · 1 comment
Closed

Cache compiled classes between scripts #32

gbrail opened this issue Dec 18, 2013 · 1 comment

Comments

@gbrail
Copy link
Contributor

gbrail commented Dec 18, 2013

Rhino generates bytecode every time a script is compiled, and that bytecode goes into the PermGen nutil the script is no longer used and it gets GCed. In a server with hundreds of node.js scripts running, if each is using a large set of modules such as Express, then we end up with hundreds of megabytes of bytecode sitting in PermGen.

We can drastically reduce the memory usage in large deployments by caching bytecode. For instance:

  • SHA1 hash each script before compiling it
  • Check a thread-safe cache to see if the same script has already been compiled
  • Only compile if the bytecode is not cached
  • Make the cache use weak / soft / whatever references so that it will be GCed on memory pressure and not grow forever.
@gbrail
Copy link
Contributor Author

gbrail commented Mar 18, 2014

Fixed in 0.7.1.

@gbrail gbrail closed this as completed Mar 18, 2014
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

1 participant