-
Notifications
You must be signed in to change notification settings - Fork 797
Memory leak in Sprockets v3.0 #35
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
Comments
I don't know if this is a memory leak. What I think it is happening here is that you code is compiling the assets when rendering and this is growing the memory usage (what is expected if you are compiling the asset). I think in sprocket 2 we cache it somehow. @josh can confirm that |
Woah, definitely curious what changed in the memory growth between 2.x and 3.x. Any addition ways to reproduce this would be helpful. Its interesting that your trying to inline the result of the asset. Though, I'd probably advise against this practice since you're using |
One thing I'd be curious if you could try is to configure the size of the local in memory cache. Right now it defaults to 4096. sprockets/lib/sprockets/cache.rb Line 63 in 2baf38c
Try dropping that to like 1024 and see what happens. |
@josh The reason we need the assets inline with HTML is because the page is downloaded to a mobile device where it must be loadable into a WebView at any time, even while the device is offline. That's why we need everything packed into HTML. The assets are precompiled and minified during code deployment and served by the web server, rather than by Rails. However, this page has some user-specific parts (a view partial is rendered within the The CSS file is rather large, mainly due to embedded web fonts via data URLs. The JS file is much smaller, but I suppose file size can only affect the speed at which memory is consumed. Hope this provides some context. What would the cache size tweak do? |
@josh @rafaelfranca Any additional thoughts on this issue? What is the best and preferably future-proof way of circumventing the problem? Thanks! |
You should definitely try serving those from regular ActionView methods. Its going to be much faster. You really don't want to be exec'ing CoffeeScript or Sass to render those inline components.
Could you give changing the cache size a try please. That would hopefully narrow down the issues to Sprockets cache references. Reducing those references may limit how many cached objects are kept around in memory possibly contributing to the memory warning. |
Hm, I may be wrong, but aren't you describing how to circumvent a buggy behavior: if an asset is already precompiled, shouldn't
To which "regular" ActionView methods you're referring to? I'm not familiar of any other way of loading assets other than via the above-mentioned Sprockets interface ( |
No, its never worked that way. |
Gotcha. All right, thanks for the info! |
If you have Is there anyway you can test the cache size limit idea I had? I don't a reproducible example to try myself. |
No, the
Does this mean that
No, unfortunately, I cannot promise that I'll be able to try out the cache tweak, since we're talking about the production environment. |
|
Strange, it is not How do I get the file path on the file system then? The precompiled asset contains its digest in the file name and I just cannot use the file name. |
|
So it shouldn't be |
Please ignore, I missed the |
This AV helper might also be useful instead https://github.com/rails/sprockets-rails/blob/6f5a37cfc7e5e71e2a7e1d1c002448dc374f1324/lib/sprockets/rails/helper.rb#L67-L90 |
OK, will check. Thanks! |
Hello,
I'm not sure how to be more precise, but there seems to be a memory leak in the asset fetching code in v3.0.
For some reason, we need to provide an HTML page with all assets embedded into the page. That being said, page's
<head>
looks like this:In some cases it takes 5 seconds for this part to render (according to New Relic). Also, there is a memory usage spike that eventually leads to "Memory limit reached" errors (on Heroku).
The problem vanished when I reverted to v2.12.
Please mind that this is happening in production and that assets have already been minified during code deploy.
Thanks!
Edit: Fixed some typos.
The text was updated successfully, but these errors were encountered: